LaTex - how to create boxes with fixed heights and widths, with enclosed text that is vertically and horizontally aligned?
Asked Answered
M

3

26

This is for creating flashcards in LaTeX. My printer doesn't support duplex printing - which packages like flashcards and flacards seem to require - so I am trying to create a two-column arrangement as follows on each page:

[Col1: Front side of the card] [Col2: Back side of the card]

Each row would correspond to a single flashcard. The plan is to cut each row up, fold them along the middle and staple them to create a "card".

The question: how best can I create a single box with a specified height and width, and with the text in it aligned vertically?

I am relatively new to Latex, so this cripples my options. I don't need full, detailed answers necessarily - any pointers at all in the right direction would help immensely! Any suggestions on alternative methods to achieve what I'm shooting for would also be helpful.

Many thanks!

Monagan answered 9/1, 2010 at 17:12 Comment(1)
shouldn't this be moved to tex.stackexchange.com ?Supercharge
S
31

Suppose you want to create the box of 40pt height and 3cm width:

\vbox to 40pt {\vfil
\hbox to 3cm{Some info}%
\vfil
}
Snapshot answered 9/1, 2010 at 21:50 Comment(3)
This is the way to do it. It will be easier when laying out the page if you put all margins to 0pt.Guimond
Thank you. However, I did manage to get a result I wanted through tables, but will revisit this arrangement soon.Monagan
For any other newbs like me who want to use this to place a centered equation in the middle of the box, let me save you several hours: Replace {Some info} with {\fil \ensuremath{Some eqn} \hfil}.Climate
H
2

You could use whatever packages to make your flashcards, and then save the output in pdf format (use pdflatex for example). Then, make another document in Latex which uses pdfpages package and uses its nup option to print two pages per page. Pdfpages has a lot of options, to fine-tune the page layout. That gives you all the power of the other packages for your use.

Hindermost answered 9/1, 2010 at 17:28 Comment(0)
M
1

My TikZ-based solution with two scopes and nested fbox and parbox: text is horizontally (due to \centering) and vertically centered in the two boxes/columns, widths and heights may all be tuned.

\documentclass[tikz,multi=false,border=5mm]{standalone}
\usepackage{lipsum}

\begin{document}
\begin{tikzpicture}
\begin{scope}
  \node (0,0) {\fbox{\parbox[c][100mm][c]{65mm}{\centering%
    \lipsum[1]
  }}};
\end{scope}

\begin{scope}[xshift=75mm]
  \node (0,0) {\fbox{\parbox[c][120mm][c]{65mm}{\centering%
    Some text\\%
    \ \\%
    \lipsum[2]
  }}};
\end{scope}
\end{tikzpicture}
\end{document}

screenshot of output

Manzo answered 19/4, 2019 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.