LaTeX/Boxes
Help and Recommendations
You can help update it, discuss progress, or request assistance.
| | This module may require a complete rewrite in order to suit its intended audience. You can help rewrite it. Please see the relevant discussion. |
Contents
TeX boxes and glue overview [ edit | edit source ]
A box is the TeX term for an invisible container that can hold a visible element, nothing, or other boxes. Glue is the TeX term for an invisible connector that determines the relative position of joined boxes. Each separate visible element contained within a TeX document is contained within a box. A visible element can be a letter, image, geometric shape, etc. TeX builds pages by gluing boxes together according to the default TeX rules, default LaTeX rules, or document commands. In a typical document, letter boxes are glued to other letter boxes to form words, which are then elastically glued to other words to form sentences. Sentences are broken into lines and placed in paragraph boxes. Elastic glue is squeezed or stretched to fully justify lines within paragraph boxes. Paragraph boxes are glued to diagram boxes, and so on.
While it is true that boxes can hold other boxes, not all commands that can generate boxes can be used within all other commands that can generate boxes. There are often workarounds for these limitations.
The size of a box is typically related to the size and position of its contents, but it doesn’t have to be. Many box commands accept custom widths and/or heights, and there are other commands that affect the shape and position of boxes. Boxes are placed relative to other boxes, while visible elements are placed relative to the boxes which contain them.
boxes [ edit | edit source ]
character boxes [ edit | edit source ]
TeX character boxes have three dimensional properties:
Character boxes are glued together at the baseline.
parbox, minipage, and pbox [ edit | edit source ]
A \parbox is a box of specific width formatted in paragraph mode. In paragraph mode, text is broken into lines and lines are broken into pages.
pos selects which baseline to join. It can be top, bottom, or center. This parameter is often confusing to new users! See the special note below.
contentpos positions the contents of the box within the box. It can be one of center, top, bottom or spread. Note that contentpos has no effect if the box is not larger than the text it contains.
\begin < minipage >[pos][height][contentpos] < width >text \end
special notes on the pos parameter [ edit | edit source ]
If the contentpos is present and not the same as pos and pos is not center, the \parbox will align at its borders.
makebox and mbox [ edit | edit source ]
Makebox creates a single-line box, optionally of fixed width, but otherwise large enough to hold its contents. Note that the width does not have to be wider than the contents: for instance, setting width to 0 typesets the content without changing the current position. (E.g., this would allow for an overstrike.) Makebox is typically used to prevent hyphenation (see Hyphenation) or simply to keep text that belongs together from being placed on separate lines. You cannot place line breaks (\\) within a Makebox. mbox is the shorthand no-option version of Makebox.
The pos parameter takes a one letter value: center, flushleft, flushright, or spread the text to fill the box.
framebox and fbox [ edit | edit source ]
The command \framebox behaves identically to \makebox except that it additionally draws a box around its contents.
The following example shows you some things you could do with the \makebox and \framebox commands:
You can tweak the following frame lengths.
This prints a thick and more distant frame:
This shows the box frame of a letter.
The framed package is available that adds the framed environment which provides an an easy way to frame a paragraph within a document:
savebox/usebox/newsavebox [ edit | edit source ]
A savebox is a non-rendered box that is saved for later repeated rendering via the usebox command.
The command \newsavebox creates a placeholder for storing content; the command \savebox stores the specified content in the placeholder without rendering it in the document; and \usebox renders the content of the placeholder into the document.
colorbox and fcolorbox [ edit | edit source ]
fancybox [ edit | edit source ]
The fancybox package provides additional boxes.
box modifiers [ edit | edit source ]
raisebox [ edit | edit source ]
Now that we control the horizontal, the obvious next step is to go for the vertical. No problem for LaTeX. The
rotatebox [ edit | edit source ]
resizebox and scalebox [ edit | edit source ]
The graphicx package features additional boxes.
Minipage latex что это
Put contents into a box that is width wide. This is like a small version of a page; it can contain its own footnotes, itemized lists, etc. (There are some restrictions, including that it cannot have floats.) This box will not be broken across pages. So minipage is similar to \parbox (see \parbox ) but here you can have paragraphs.
This example will be 3 inches wide, and has two paragraphs.
The required argument width is a rigid length (see Lengths). It gives the width of the box into which contents are typeset.
The optional argument position governs how the minipage vertically aligns with the surrounding material.
(synonym m ) Default. Positions the minipage so its vertical center lines up with the center of the adjacent text line.
Align the baseline of the top line in the minipage with the baseline of the surrounding text (plain TeX’s \vtop ).
Align the baseline of the bottom line in the minipage with the baseline of the surrounding text (plain TeX’s \vbox ).
To see the effects of these, contrast running this
The final optional argument inner-pos controls the placement of contents inside the box. These are the possible values are (the default is the value of position ).
Place contents at the top of the box.
Place it in the vertical center.
Place it at the box bottom.
Stretch contents out vertically; it must contain vertically stretchable space.
Footnotes in a minipage environment are handled in a way that is particularly useful for putting footnotes in figures or tables. A \footnote or \footnotetext command puts the footnote at the bottom of the minipage instead of at the bottom of the page, and it uses the \mpfootnote counter instead of the ordinary footnote counter (see Counters).
This puts the footnote at the bottom of the table, not the bottom of the page.
If you nest minipages then there is an oddness when using footnotes. Footnotes appear at the bottom of the text ended by the next \end
This puts a table containing data side by side with a map graphic. They are vertically centered.
LaTeX-Tutorial.com
In this tutorial, we are going to learn how to use the minipage environment.
1. What is the minipage environment?
The short answer is that minipage is an environment to produce parboxes in LaTeX. Probably this doesn’t tell anything to you, so we are going to break it down and see what it means. To do so, however, we will have to dive into the basics of LaTeX and its underlying system TeX. Don’t worry if you don’t care about technical details: I am going to put it in simple terms, so it is not a dense read, and you have the basic ideas to understand the following sections.
Parboxes are nothing but boxes written in paragraph mode. Here arise two concrete questions: first, what are boxes, and second, what is paragraph mode.
Let’s tackle the first. When LaTeX processes your input text, it is always in one of three modes:
Paragraph mode is LaTeX’s normal mode, the one used when processing ordinary text. In paragraph mode, your input is regarded as a sequence of words and sentences to be broken into lines, paragraphs, and pages.
To better understand this, we have to answer the first question and explain what boxes are.
So the minipage environment produces parboxes, which are boxes written in paragraph mode. That is, the environment contains a sequence of words that LaTeX writes in paragraph mode (so that it splits them into lines, if necessary) and then becomes a single box, a TeX indivisible unit. We will see that, in fact, the minipage can contain other boxes that are not words, but that will regardless be processed in paragraph mode.
2. Basic use
Now let’s see how to use the minipage environment in practice. This environment takes as a mandatory argument the width of the text since TeX needs to know, before breaking text into lines, how wide the lines should be. Of course, this argument is a TeX dimension.
Here is an example of how you can use it:
This output may surprise you; in that case, you haven’t understood the first section of the tutorial. But don’t worry, we are going to review what is happening here.
3. Indentation in minipage environment
You can see that there is no indentation at the beginning of the paragraph inside parboxes. This is because LaTeX sets the \parindent parameter, which specifies the amount of indentation, to zero inside a parbox. You can specify any other value with the \setlength command. For example:
This code produces the following result:
Other document distances may be changed as well, such as the margins, but it is usually not necessary since you determine explicitly the width of the minipage.
4. Text alignment
By default, LaTeX text is justified, and the minipage environment is not an exception. However, you can change the text alignment inside the environment using the tools provided by the ragged2e package
5. Vertical alignment of minipage content
In previous examples, the paragraphs produced by the minipage are positioned vertically so that the center of the box is aligned with the center of the text line. This can be modified with an optional first argument:
In this example, we test how different positioning options look:
We can further customize how high or low a minipage box is with respect to the baseline of text using the \raisebox command. This command takes two mandatory arguments:
In the following example, we illustrate its use:
Compiling this code yields the following output:
This code is really overkilling: since lines, once processed by TeX, become boxes, we could have obtained the same result in this case without minipage. However, if we wanted to insert images, for example, the minipage environment would be needed to create a single box from all the content.
6. Footnotes in LaTeX minipage
As a final note, it is interesting to note that, when used inside a minipage environment, the footnote command puts a footnote at the bottom of the parbox produced by the environment. Here is an illustrative example:
which yields the following:
7. Height and inner position options
There are other, less common options, that the minipage environment admits. The general syntax when beginning the environment is the following:
In the following example you can see how the different inner positions look:
8. Inserting figures in minipage
You may think that inserting a figure inside a minipage environment consists of just writing the corresponding figure environment inside. If you do this, however, you will be faced with an error. This is due to the fact that the figure environment is a floating environment, while the minipage isn’t.
Still, you can load the graphicx package and use \includegraphics to insert an image inside a minipage environment, because this command creates a box with the figure file you pass to it, and it is not a floating object.
Observe in the following example how the behavior of the figure environment can be copied inside a minipage environment:
This code produces the following result:
The syntax of the \captionof command is the following:
Although less common, you may not want the figure inside the minipage environment to be printed on the list of figures nor referenced in any way. For this purpose, you can write the caption with \captionof* and the
caption will be typeset without label and without entry to the list of figures.
9. Add a frame to minipage
We can add a frame surrounding the minipage environment using LaTeX’s \fbox command. This command puts a frame around the box passed to it so that the code:
which yields the following result:
We can even change the width of the box frame and the separation between the text and the frame adding the lines:
to the preamble of the document. The first of these lines sets the width of the frame and the second sets the separation between the text and the frame; both have to be set to a TeX dimension. The output, in this case, is shown below:
10. Background color of minipage
The most versatile tool to work with colors in LaTeX is the xcolor package. This package provides multiple tools, but the one we are interested in here is the \colorbox command. This command takes as a:
In the next example we show how to easily color a minipage:
A minipage environment with a pink background
11. rotate minipage environment
Since the minipage environment produces a box, an indivisible unit, it can be rotated. To do so, we can use the command \rotatebox that comes with the graphicx package (usually used to insert images). This command takes two
mandatory arguments:
In the following example, you can see how to use it:
compiling this code yields the following result:
Rotated text using the minipage environment
12. Two column’s content
The minipage environment can be used to produce double-column content in a single-column document and vice versa. Let me show you how to do it.
In the first case, we only have to put two minipage environments side by side, always making sure that the two boxes generated fit in the same line; in another case, they will be printed one on top of each other.
In the following example we use this possibility to add an explanation next to a figure:
This code produces the following image:
As you can see, the code contains some extra space to separate the figure from the previous paragraph, and the
explanation from the figure. The rest of the example is the same as we have seen previously, for example when using captions to insert images.
In a similar manner, inside a two-column document, you can use a single minipage environment that spans the whole text width to produce single-column text.
Conclusion
Along with this tutorial we have seen how to deal with the minipage environment:
However, in all of these explanations, there is a common idea that has been always present (either implicit or explicitly): the idea of TEX’s boxes.
As was stated at the beginning, boxes are one of the fundamental objects (along with glue) that TEX uses to print our documents. So if all these explanations helped you understand what is a box, maybe you have extracted one of the most important ideas of this tutorial. Once you understand what a box is and how you can deal with it, all your LATEX live will be much easier!
minipage: большой бокс и маленькая страница
TeX формирует страницы, выстраивая их из блоков — боксов. Элементарным боксом является каждая буква. Буква приклеивается к другим буквам, формируя слово, которое, в свою очередь, склеивается с другими словами. Для этого используется эластичный «клей», способный растягиваться или сжиматься так, чтобы в точности заполнить строку. Таким образом, TeX работает только с боксами и клеем.
Боксом может быть не только буква. Вы можете поместить в бокс практически все, что угодно, например, другие боксы. Каждый бокс при этом обрабатывается LaTeX’ом так, как если бы это была отдельная буква.
Вы можете упаковать любой абзац в бокс с помощью команды:
Чаще всего minipage используется в сокращенном варианте:
Разница между обоими вариантами видна из следующих примеров. Для наглядности, каждый minipage дополнительно помещен в «бокс с границей» — \fbox
Сокращенный вариант minipage
Полный вариант
Примеры использования minipage
Две картинки с подписями, размещенные в одной строке:
Картинка в одной строке с текстом:
Матрица из картинок:
Две таблицы в одной строке:
Читайте также
Комментарии
Дмитрий Храмов
Компьютерное моделирование и все, что с ним связано: сбор данных, их анализ, разработка математических моделей, софт для моделирования, визуализации и оформления публикаций. Ну и за жизнь немного.









