GeneralDynamic Minipage Sizing

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
lanew
Posts: 3
Joined: Mon Nov 21, 2011 12:57 am

Dynamic Minipage Sizing

Post by lanew »

I'm trying to format a document with two groups of text, one on the left, and one on the right with blank space in the middle. At the moment I use two minipages with \hfill in between to push one to the right. This works fine; however, if I edit the font inside the minpage environment I have to change the width of the minipage. Is there a way to have dynamic sizing in the minipage environment so if I change the text it resizes itself? Or should I go about this another way?

Code: Select all

\documentclass[10pt]{article}
\begin{document}
\begin{minipage}[H]{0.3\textwidth}
Something \\
Something Else
\end{minipage}
\hfill
\begin{minipage}[H]{0.3\textwidth}
Something \\
Something Else
\end{minipage}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10358
Joined: Mon Mar 10, 2008 9:44 pm

Dynamic Minipage Sizing

Post by Stefan Kottwitz »

If you would like to have automatic size of the text, you should fix the space between. Otherwise, LaTeX cannot know to which width the text should be adjusted.

I recommend using the tabularx package and the environment with the same name, such as

Code: Select all

\documentclass[10pt]{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{X@{\hspace{2cm}}X}
\blindtext & \blindtext
\end{tabularx}
\end{document}
Stefan
LaTeX.org admin
lanew
Posts: 3
Joined: Mon Nov 21, 2011 12:57 am

Dynamic Minipage Sizing

Post by lanew »

Thanks very much for your reply Stefan!

I actually just came back to post my new findings and saw your reply. I decided to go with the regular tabular environment as follows:

Code: Select all

\documentclass[10pt]{article}
\begin{document}
\begin{tabular}{l}
Something \\
Something
\end{tabular} \hfill % Push table to right
\begin{tabular}{l}
Something \\
Something
\end{tabular} % To align with right margin
\end{document}
This has worked out perfectly. Thanks again!
Post Reply