2

I would like to get the following in Latex (without the table borders):

enter image description here

Here's my (incorrect) code:

\begin{enumerate}
  \item \begin{tabular}{c c p{10 cm}}
    $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ & = & the amplitude\newline for a particle to propagate from $y$ to $x$\newline (in the Heisenberg picture).
  \end{tabular}

This produces the following (ignore the '4'):

enter image description here

Can you suggest the correct code?

  • 1
    Welcome to the site! Have you seen tex.stackexchange.com/questions/12703/… – cmhughes Jan 19 '16 at 15:00
  • Yes. But, I want the item number 1 centered not in the left center of the table, but on the upper left corner. – nightmarish Jan 19 '16 at 15:22
  • @failexam - How about \begin{tabular}[t]{c c p{10 cm}}? Note the [t]. – Arash Esbati Jan 19 '16 at 15:56
  • but you said ignore the '4'.... perhaps you want \begin{tabular}[t].... – cmhughes Jan 19 '16 at 15:56
  • @ Arash. This places the item number in the lower left corner, not the upper left corner. I want the item number in the upper left corner. – nightmarish Jan 19 '16 at 16:00
1

I'm not sure if it's the best solution, but adjustbox can help to align different kind of boxes.

\documentclass{article}

\usepackage{amsmath,array, adjustbox, lipsum}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\lipsum[1]
\begin{enumerate}
    \item \adjustbox{frame, valign=t, center}{\begin{tabular}{c c C{6cm}}
              $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ & = & the amplitude\newline for a particle to propagate from $y$ to $x$\newline(in the Heisenberg picture).
        \end{tabular}}
        \item Some other text
\end{enumerate}
\end{document}

enter image description here

Update: frame inner margins and tabular inside adjustbox

From OP's comment, it seems some larger inner margin is needed inside previous frame.

adjustbox offers option margin (always placing it before frame) which fixes inner box margins. This option accepts one, two or four values for setting all margins, horizontal and vertical or left, bottom, right and top margin. If only some margin between top line and first inner text line, option could be margin=0 0 0 2ex. In next code only two values are used.

Apart from this, adjustbox also offers special syntax for specific environments, like tabular. Therefore an option like tabular=ccc means that second parameter will have a three tabular structure. It saves some typing. This option can be used with \adjustbox command or with adjustbox environment. In first case an additional \\ must be added after last tabular line.

Following code shows all three possible declarations:

\documentclass{article}

\usepackage{amsmath,array, adjustbox, lipsum}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\lipsum[1]

\begin{enumerate}
    \item \adjustbox{margin=0ex 2ex, frame, valign=t, center}
          {\begin{tabular}{c c C{6cm}}
              $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ 
              & = & 
              the amplitude\newline for a particle to propagate 
                 from $y$ to $x$\newline(in the Heisenberg picture).
           \end{tabular}}
    \item \adjustbox{margin=0ex 2ex, frame, valign=t, center, 
          tabular={c c C{6cm}}}{
              $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ 
              & = & 
              the amplitude\newline for a particle to propagate 
                 from $y$ to $x$\newline(in the Heisenberg picture).\\}
    \item \begin{adjustbox}{margin=0ex 2ex, frame, valign=t, center,  
                  tabular={c c C{6cm}}}
              $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ 
              & = & 
              the amplitude\newline for a particle to propagate 
                 from $y$ to $x$\newline(in the Heisenberg picture).
          \end{adjustbox}
\end{enumerate}
\end{document}

enter image description here

  • How can I center the lines of the third box? And also how I center the entire table as a whole across the page? – nightmarish Jan 19 '16 at 16:19
  • Alright. The following code centers the line of the third box: \documentclass{article} \usepackage{amsmath,array, adjustbox} \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}} \begin{document} \begin{enumerate} \item\adjustbox{valign=t} {\begin{tabular}{c c C{7 cm}} $\langle 0 \lvert \phi(x)\phi(y)\lvert 0 \rangle$ & = & the amplitude\newline for a particle to propagate from $y$ to $x$\newline (in the Heisenberg picture). \end{tabular}}. – nightmarish Jan 19 '16 at 16:27
  • Now, just tell me how to center the table as a whole? – nightmarish Jan 19 '16 at 16:27
  • @failexam: Updated answer with adjustbox center option, which works if your tabular is not longer than the rest of line. 10cm for third column was too long. Suppres frame option for the final result. New C column type (from tex.stackexchange.com/a/12712/1952) centers the contents of third column. – Ignasi Jan 19 '16 at 17:06
  • Please give a way to slightly increase the spacing between the top line of the frame and the first line of text. That is, I need to increase the top margin of the box. – nightmarish Jan 19 '16 at 18:23
0

If you add

Edit: \usepackage{array}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}} %% horizontal centering
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}} %% vertical centering

in your preamble.

Than you can choose P{10cm} or M{10cm} instead of p{10cm}.

  • 1
    You should to mention, that for your solution that package array is needed. – Zarko Jan 19 '16 at 16:26
  • Thanks I wasn't 100% sure, so i didn't want to give to much code. – Arne Timperman Jan 19 '16 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.