Text Formattingfancybox | Two adjacent framed Boxes with same Height

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
EmilioLazo
Posts: 15
Joined: Sat Jul 16, 2011 1:59 am

fancybox | Two adjacent framed Boxes with same Height

Post by EmilioLazo »

Hello!

I'm trying to achieve having two cells the same height in order to frame them with an ovalbox but don't know how to do this. I did try with an \ovalbox outside of a \parbox (what I call "first try"), and the same but with a tabular outside (second try). Also, following a trick found in [1] I did try with \raisebox and {lrbox} also without success.

What I want is a way to have two adjacent boxes with equal heights to frame them with \ovalbox, \framebox or \shadowbox (something like vertical centering the smallest box). Both texts inside boxes are arbitrary and comes from commands defined with \newcommand and generally I don't know which one is the tallest.

Code: Select all

\documentclass{article}
\usepackage{fancybox}
\usepackage[vmargin={3cm,3cm},hmargin={1cm,1cm},footskip=0pt,headsep=0pt,headheight=0pt]{geometry}
\setlength{\parindent}{0pt}

\begin{document}
% First try
\ovalbox{%
\parbox{8cm}{%
some text
}}
\hfill
\ovalbox{%
\parbox{8cm}{%
some different \par
text
}}

% Second try
\begin{tabular*}{\textwidth}{ll}
\ovalbox{%
\parbox{8cm}{%
some text
}}
&
\ovalbox{%
\parbox{8cm}{%
some different \par
text
}}
\end{tabular*}

\end{document}
Thanks in advance to anyone which points me in the right direction!

[1] LaTeX/Tables – Wikibooks, open books for an open world

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

fancybox | Two adjacent framed Boxes with same Height

Post by Juanjo »

Since you don't know the heights of every chunk of text, you should first measure it. Then you can write boxes with the right height. The following example may give you some insights:

Code: Select all

\documentclass{article}
\usepackage{fancybox}
\usepackage[vmargin={3cm,3cm},hmargin={1cm,1cm},noheadfoot]{geometry}
\setlength{\parindent}{0pt}

\begin{document}

% Auxiliary lengths and box
\newlength{\TotalHeightI}
\newlength{\TotalHeightII}
\newsavebox{\TemporaryBox}

% Macros that yield the text inside the two boxes
\newcommand{\SomeText}{Text text text}
\newcommand{\SomeWords}{Words words words \par More words words \par And even more words}

% It is assumed that the boxes width will be 8cm. Change as needed.
% We first measure the total height of every box
\sbox{\TemporaryBox}{\parbox{8cm}{\SomeText}}
\setlength{\TotalHeightI}{\dimexpr\dp\TemporaryBox+\ht\TemporaryBox}
\sbox{\TemporaryBox}{\parbox{8cm}{\SomeWords}}
\setlength{\TotalHeightII}{\dimexpr\dp\TemporaryBox+\ht\TemporaryBox}

% We actually write the boxes with the correct total height
\ifdim\the\TotalHeightI<\the\TotalHeightII
   \ovalbox{\parbox[c][\TotalHeightII][c]{8cm}{\SomeText}}\hfill
   \ovalbox{\parbox[c][\TotalHeightII][c]{8cm}{\SomeWords}}
\else
   \ovalbox{\parbox[c][\TotalHeightI][c]{8cm}{\SomeText}}\hfill
   \ovalbox{\parbox[c][\TotalHeightI][c]{8cm}{\SomeWords}}
\fi

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply