开发者

Latex minipage to align groups of text

开发者 https://www.devze.com 2022-12-08 12:30 出处:网络
I am trying to get two minipage sections to show up next to each other. They always show up one underneath the other currently below is an example of my .tex

I am trying to get two minipage sections to show up next to each other. They always show up one underneath the other currently below is an example of my .tex

Example:

\begin{minipage}[b]{1in}
   Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}
\begin{minipage}[b]{1in}
   Hello 开发者_StackOverflow中文版World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}


You need to remove the newline from one minipage to the other.

\begin{minipage}{1in}
   Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}\begin{minipage}{1in}
   Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}

You can keep the newline if you fake it with the comment character

\begin{minipage}{1in}
   Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}%
\begin{minipage}{1in}
   Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}

Note that if the accumulated width of minipages is too wide, the next one will drop to the next line (kind of like floating divs... if you do css). In order to worry about this less, I generally give my minipages a width which is a fraction of the line width. For instance \begin{minipage{0.25\linewidth}. You have to account for a little separation and I dont know what relevant tex variables handle the glue in this case, but if I keep the total less than or equal to 0.99\linewidth things seem to be ok.

HTH


When I run the following through pdfLaTeX I get a document with two vertical columns, aligned next to one another;

\documentclass{article}
\begin{document}
\begin{minipage}[b]{1in} Hello World
akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd \end{minipage}
\begin{minipage}[b]{1in} Hello World
akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd \end{minipage}
\end{document}

In the future, please use code tags around your examples.


You could also just set them in a two column table:

\begin{tabular}{ p{0.5\textwidth} p{0.5\textwidth} }

column one blah blab blah

&

column two blah blab blah

\tabularnewline
\end{tabular}


You can use the \textwidth command to make them fit:

\documentclass{article}
\begin{document}
\begin{minipage}[b]{0.5\textwidth}
Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}
\begin{minipage}[b]{0.5\textwidth}
Hello World akdjfasljdfkjasjdfjsadkflkjksadflkaskjdfsadlflkjsafdalkjsfd
\end{minipage}
\end{document}

(learnt this trick here)

Do make sure there aren't any blank lines between the end of one minipage and the start of another. And you may want to use \noindent before the first \begin{minipage} to get the columns to be aligned the same as the text with respect to the left margin.


You should increase the minipage width from 1in to say 5in or 6cm

For example:

\begin{minipage}[b]{1in}

should be:

\begin{minipage}[b]{5in}
0

精彩评论

暂无评论...
验证码 换一张
取 消