I'm writing a LaTeX document into which I want to put two boxes, in a row next to each other, which will contain varying length content.
I want each box to be the same height, and that height needs to be the height necessary to contain the content in the box with the most content, i.e. both boxes should be the height of the taller of the two. Lastly, I want to put a border partway around one of the boxes. The "each box is the same height" comes into play, because I want the border around the box with the border to appear to contain the text in the other, unbordered box.
In a word processor like Word / Pages / etc; I would do this by making a 1 row, 2 column table; where I apply the box border by arbitrarily styling the borders of one of the cells. If you put a lot of content in one cell, the other cell in the row grows to match it.
I've tried to do it in LaTeX and got halfway there. I can get the two boxes, with two minipages. And I can get the box outlined with \newmdenv
. What I can't seem to do is, get the two boxes to be the same size with varying length content. If I put "big" content in the box with the border. But if I put "small" content in that box, then it isn't big enough for the top & bottom to appear to "contain" the other box.
\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage{mdframed}
\geometry{letterpaper}
\usepackage{lipsum} %used to generate dummy text
\newmdenv[leftline=false]{leftcap}
\title{latextest2.tex}
\author{test}
\begin{document}
\begin{figure}[!h]
\begin{minipage}[t]{0.5\linewidth}
\vspace{12pt}
\lipsum[1]
\end{minipage}
\hspace{0.5cm}
\begin{minipage}[t]{0.5\linewidth}
\vspace{0pt}
\begin{leftcap}
\lipsum[2]
\end{leftcap}
\end{minipage}
\end{figure}
\end{document}
In the code above, the lipsum[1]
paragraph is longer than the lipsum[2]
paragraph, so that box gets bigger. How can I make both of those minipage boxes the same size? Or alternately, what other approach can I use to get the behaviour of Word's 2 column 1 row table?
UPDATE
Thanks for your answers, Werner and Martin. I was able to get Werner's to work with a little homework. I couldn't quite get Martin'sto work all the way.
Below, I added in Martin's cfbox
command that he linked to, and using that I can get he box to go around the minipage
in the way that I want, for this particular content.
The only problem is, by setting the minipage
height explicitly it is not flexible anymore. By this I mean, the box on the right is always the same height as the box on the left. But what I want is for both boxes to be as high as the tallest of the two boxes. So, for example, if I add content to the right box, I want that box to grow. I think what is necessary here is the equivalent of an if/then/else
statement for the box heights.
Below is an example showing it working as far as putting the boxes around, but breaking as far as not expanding to fit the new sized content.
\documentclass[11pt]{article}
\usepackage{geometry}
\geometry{letterpaper}
\usepackage{lipsum} %used to generate dummy text
\usepackage{xcolor}
\makeatletter % Copied this from: http://tex.stackexchange.com/a/55534
\newcommand\cfbox[3][lbrt]{% Copied this from: http://tex.stackexchange.com/a/55534
\begingroup
\leavevmode
\setbox\@tempboxa\hbox{%
\color@begingroup
\kern\fboxsep{#3}\kern\fboxsep
\color@endgroup
}%
\@tempdima\fboxrule
\advance\@tempdima\fboxsep
\advance\@tempdima\dp\@tempboxa
\hbox{%
\hskip-.5\fboxrule
\lower\@tempdima\hbox{%
\vbox{%
\in@{t}{#1}%
\ifin@
{\color{#2}%
\hrule\@height\fboxrule
}%
\fi
\hbox{%
\in@{l}{#1}%
\ifin@
{\color{#2}%
\vrule\@width\fboxrule
}%
\fi
\vbox{%
\vskip\fboxsep
\box\@tempboxa
\vskip\fboxsep}%
\in@{r}{#1}%
\ifin@
{\color{#2}%
\vrule\@width\fboxrule
}%
\fi
}%
\in@{b}{#1}%
\ifin@
{\color{#2}%
\hrule\@height\fboxrule
}%
\fi
}%
}%
\hskip-.5\fboxrule
}%
\endgroup
}
\title{latextest2.tex}
\author{test}
\usepackage{calc}
\newsavebox\mybox
\begin{document}
\begin{lrbox}{\mybox}
\begin{minipage}[t]{0.5\linewidth}
\lipsum[1]
\end{minipage}%
\end{lrbox}%
\usebox\mybox
\hspace{0.5cm}
\cfbox[tbr]{black}{% As suggested by Martin Scharrer at http://tex.stackexchange.com/a/56883
\begin{minipage}[t][\ht\mybox+\dp\mybox]{0.5\linewidth}
\lipsum[2]\par\lipsum[3]
\end{minipage}
}
\end{document}