# Four ways to align two elements next to each other in LaTeX

Of course there are more than just four ways to do layout like aligning elements next to each other. In this post, I just want to summarize the four ways I tend to use:

• Flowfram
• Table
• Column
• Minipage

Note that all code is stripped in order to reduce the length of this post.

## Flowfram

Flowfram is a package which has to be included and configured. In the following, I will only list the way how to align two simple image elements next to each other, even though this package provides much more possibilities. Please refer to the documentation for more informations.

% ...
usepackage{flowfram}

newflowframe{0.49textwidth}{textheight}{0pt}{0pt}[columnone]
newflowframe{0.49textwidth}{textheight}{dimexpr2blockwidth+3columnsep}{0pt}[columntwo]

begin{document}

begin{figure}[!h]
centering
includegraphics[width=.25textwidth]{test-white.png}
caption{Caption}
label{fig:my_label1}
end{figure}

pagebreak

begin{figure}[!h]
centering
includegraphics[width=.25textwidth]{test-white.png}
caption{Caption}
label{fig:my_label2}
end{figure}

% ...

## Table

Good old Table is a method of aligining items too! Note that it is not the inteded purpose of a table cell to contain much more than just text, so you might find additional difficulties inserting an image or a list inside a table. Important for use as a layout tool is simply not to add the borders of the table cells and rows. That simply means no “|” between the float specifiers as well as no \hline or similar in the table.

In the following example, I usepackage{tabularx} in order to get both items the same horizontal space.

begin{table}[!h]
centering
begin{tabularx}{textwidth}{XX}
{
Test left
} &  {
Test right
}
end{tabularx}
end{table}

## Column

Columns are the way to go for longer parts of the document, or if you even want the whole document splitted into two elements next to each other. You may use the multicol package for a simple solution:

usepackage{multicol}

begin{document}
begin{multicols}{2}
This text will be split into two columns.
end{multicols}

## Minipage

Minipage is not a package and should be provided automatically by your LaTeX distribution. A minipage is what its name says: a new float environment, a new page, but mini. You can wrap nearly anything inside a minipage and size it the way you want. To align two minipages next to each other, you could do so:

begin{figure}[htbp]
% minipage with text
begin{minipage}{0.45textwidth}
Left hand side
end{minipage}
% Fill the space in between
hfill
% minipage with image
begin{minipage}{0.45textwidth}
% textwidth is defined by the minipage, inside here
includegraphics[width=textwidth]{test.png}
caption{An image}
label{image}
end{minipage}
caption{Caption of both sides. Optional.}
end{figure}

## What to use when?

Answer the following questions to get to a result. Note that this selection is only based on my current opinion and knowledge and therefore up for changes and challenges.

Do you need a rather configurable column setup and are you ready to read long documentations and learn about internals of a LaTeX package in order to get the most possibilities? Use Flowfram.

Do you need the elements not necessarily to be next to each other but to overflow from one to the other? Use columns.

Are the elements to be placed next to each other the same height, together do not need a specific placement and are not so much new float environments? Use a table (or longtable if longer than one page).

If you answered all these questions above with no, try minipage.

#### Tim Bernhard

Mein Name ist Tim Bernhard, geboren bin ich am 2. August 1996. Ich besuchte die Kantonsschule in Wiedikon und schloss diese im Frühling 2015 ab. Als Maturaarbeit habe ich meine Leidenschaft für Programmiertechnische Projekte mit Hoffnungen für die Zukunft verbunden und das Unternehmen Bernhard Webstudio gegründet.

This site uses Akismet to reduce spam. Learn how your comment data is processed.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.4991650879383087, "perplexity": 2198.2933861559027}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-39/segments/1568514570830.42/warc/CC-MAIN-20190915072355-20190915094355-00007.warc.gz"}