3

I have a figure that consists of multiple paragraphs of tabulars and images. At least one of these paragraphs is wider than the text width. How can I center the entire figure so that the widest paragraph is perfectly centered, and the left edge of all other paragraphs is aligned with the left edge of the widest paragraph?

For example, how can I make the following document

\documentclass{article}
\usepackage{lipsum}

\begin{document}

\fbox{\begin{tabular}{lllp{4in}}
a & b & c & \lipsum[4]
\end{tabular}}

\fbox{\begin{tabular}{lllp{3in}}
aaaa & bbbb & cccc & \lipsum[4]
\end{tabular}}

\end{document}

look like:

...**********************************************...
...******************************************.......

where . is a space and * is part of the boxed region. I don't know the width of the largest paragraph in advance.

Below is a real example. The goal is to center the entire table at once.

\documentclass{article}
\usepackage{amssymb}

\begin{document}

\begin{table}
{\bf Contexts}\\
\begin{tabular}{lllp{4in}}
  {\it Statement} & $\Pi$ & $n$ $\mapsto$ \emph{instr} &
  Maps an statement address to an statement.\\
  {\it Variable} & $\Delta$ &  $id \mapsto \emph{var}$  &Maps
  a variable ID to its value.\\
  {\it Labels} & $\Lambda$ & $\emph{label\_kind} \mapsto n$ & Maps
  a label to the address of the corresponding {\tt label} statement number.
\end{tabular}\\
\newline
{\bf Notation}\\
\begin{tabular}{lp{4.2in}}
  $\Delta \vdash e \Downarrow v$ & Expression $e$ evaluates to value
  $v$ given variable context $\Delta$ as given by the expression
  evaluation rules.\\
  $\Delta' = \Delta[x \leftarrow v]$ & $\Delta'$ is the same as
  $\Delta$ except extended to map $x$  to $v$.\\
  $\Pi \vdash p:s$ & $\Pi$ maps statement address $p$ to statement
  $s$. If $p \notin \Pi$, the machine gets stuck.\\
  $\Lambda \vdash v:p$ & $\Lambda$ maps statement label $v$ to statement
  address $p$. If $v \notin \Lambda$, then machine gets stuck. In
  addition, a well-formed machine should have $\Pi \vdash p : s$
  where $s = \texttt{label $v$}$, otherwise the machine is stuck.\
  $(\Delta, p, s) \leadsto (\Delta', p', s')$ &  An
  execution step. $p$ and $p'$ are
  the pre and post step program counters, $s$ and $s'$ are the pre and
  post step  statements, and $\Delta$ and $\Delta'$ are the pre and post
  step variable contexts. Note $\Lambda$ and $\Pi$ are currently static, thus
  for brevity not included in the execution context.\\
\end{tabular}
\caption{Operational Semantics Notation.}
\end{table}

\end{document}

Note: The answers to similar questions such as How can I center a too wide table? do not work for multiple paragraphs.

Moriambar
  • 11,466
Ed McMan
  • 389
  • Given the difficulties we're having in finding a suitable solution, perhaps it would be best to simply include the troublesome portion as your MWE. For images, check out the mwe package (which includes lipsum). – Sean Allred Aug 01 '13 at 03:03
  • @SeanAllred I added one of my real examples. – Ed McMan Aug 01 '13 at 03:39

1 Answers1

3

Update:

The idea is to box the material first and measure the width; this width is used to increase the margins with the help of adjustwidth; the material is then typeset using a varwidth environment.

\documentclass{article}
\usepackage{changepage}
\usepackage{varwidth}
\usepackage{lipsum}

\newsavebox\mybox \newlength\BoxWd

\newcommand\CenterBox[1]{% \begin{lrbox}{\mybox} \begin{varwidth}{\paperwidth} #1 \end{varwidth}% \end{lrbox}% \settowidth\BoxWd{\usebox\mybox}% \addtolength\BoxWd{-\textwidth}% \begin{adjustwidth}{-0.5\BoxWd}{-0.5\BoxWd} \usebox\mybox \end{adjustwidth}% }

\begin{document}

\lipsum[4] \CenterBox{\fbox{\begin{tabular}{lllp{5in}} a & b & c & \lipsum[4] \end{tabular}}

\fbox{\begin{tabular}{lllp{3in}} aaaa & bbbb & cccc & \lipsum[4] \end{tabular}} } \lipsum[4]

\end{document}

enter image description here

And with the code of the updated answer (I made some changes, in particular, changed \bf for \bfseries and \it for \itshape):

\documentclass{article}
\usepackage{changepage}
\usepackage{amssymb}
\usepackage{array}
\usepackage{varwidth}

\usepackage{lipsum}

\newsavebox\mybox \newlength\BoxWd

\newcommand\CenterBox[1]{% \begin{lrbox}{\mybox} \begin{varwidth}{\paperwidth} #1 \end{varwidth}% \end{lrbox}% \settowidth\BoxWd{\usebox\mybox}% \addtolength\BoxWd{-\textwidth}% \begin{adjustwidth}{-0.5\BoxWd}{-0.5\BoxWd} \usebox\mybox \end{adjustwidth}% }

\begin{document}

\lipsum[4] \begin{table} \CenterBox{% {\bfseries Contexts}\par \begin{tabular}{>{\itshape}l>{$}l<{$}lp{4in}} Statement & \Pi & $n$ $\mapsto$ \emph{instr} & Maps an statement address to an statement.\ Variable & \Delta & $id \mapsto \emph{var}$ &Maps a variable ID to its value.\ Labels & \Lambda & $\emph{label_kind} \mapsto n$ & Maps a label to the address of the corresponding {\tt label} statement number. \end{tabular}\par\smallskip {\bfseries Notation}\par \begin{tabular}{>{$}l<{$}p{4.2in}} \Delta \vdash e \Downarrow v & Expression $e$ evaluates to value $v$ given variable context $\Delta$ as given by the expression evaluation rules.\ \Delta' = \Delta[x \leftarrow v] & $\Delta'$ is the same as $\Delta$ except extended to map $x$ to $v$.\ \Pi \vdash p:s & $\Pi$ maps statement address $p$ to statement $s$. If $p \notin \Pi$, the machine gets stuck.\ \Lambda \vdash v:p & $\Lambda$ maps statement label $v$ to statement address $p$. If $v \notin \Lambda$, then machine gets stuck. In addition, a well-formed machine should have $\Pi \vdash p : s$ where $s = \texttt{label $v$}$, otherwise the machine is stuck.\ (\Delta, p, s) \leadsto (\Delta', p', s') & An execution step. $p$ and $p'$ are the pre and post step program counters, $s$ and $s'$ are the pre and post step statements, and $\Delta$ and $\Delta'$ are the pre and post step variable contexts. Note $\Lambda$ and $\Pi$ are currently static, thus for brevity not included in the execution context.\ \end{tabular} \caption{Operational Semantics Notation.}} \end{table} \lipsum[4]

\end{document}

enter image description here

One option using the changepage package and its adjustwidth environment:

\documentclass{article}
\usepackage{changepage}
\usepackage{lipsum}

\begin{document}

\lipsum[4] \begin{adjustwidth}{-2cm}{-2cm} \centering \fbox{\begin{tabular}{lllp{4in}} a & b & c & \lipsum[4] \end{tabular}}

\fbox{\begin{tabular}{lllp{3in}} aaaa & bbbb & cccc & \lipsum[4] \end{tabular}} \end{adjustwidth} \lipsum[4]

\end{document}

enter image description here

Gonzalo Medina
  • 505,128