2

I am attempting to put a tabular with another tabular to put cell entries on multiple lines. However, when doing so, it appears that the two images in adjacent cells are aligned at their baselines, as opposed to the entire contents of each cell being centered vertically. MWE below:

\documentclass[11pt]{article}

\usepackage{graphicx}
\graphicspath{{images/}}
\pdfminorversion=6
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=1.13}
\pgfplotsset{colormap={grays}{gray(0cm)=(0.5);gray(1cm)=(0)}}
\pgfplotsset{samples=3}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{table*}
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c|c|}
        \hline
        \begin{tabular}[c]{@{}c@{}}\includegraphics[width=0.3\linewidth]{finite_line_load_vert.pdf} \\
            $p=15$ kN/m \\ $a=5$ m \\ $b=15$ m \\ $c=0$ m \\ $z=$ 2 m \end{tabular} &
        \begin{tikzpicture}[framed]
            \begin{axis}[%
                view={30}{30},
                width=0.6\linewidth,
                height=3in,
                xlabel={Lateral Distance $x$ [m]},
                xlabel style={align=center, rotate=-7},
                ylabel={Lateral Distance $y$ [m]},
                ylabel style={rotate=27},
                zlabel={Vertical Stress $q_v$ [kPa]}
                ]
                \addplot3[
                patch,
                fill=white,
                opacity=0.8,
                domain=0:20,
                y domain=-5:5
                ]
                {15*2^3/(2*3.1415*(y^2+2^2))*(%
                    ((15-x)*(2*(15-x)^2+3*(y^2+2^2))/((15-x)^2+y^2+2^2)^1.5)-%
                    %
                    ((5-x)*(2*(5-x)^2+3*(y^2+2^2)))/((5-x)^2+y^2+2^2)^1.5))};
                \addlegendentry{$q_v$}
            \end{axis}
        \end{tikzpicture} \\ \hline
        %
        \multicolumn{2}{|c|}{\vbox{%
                \begin{equation*}
                E=mc^2
                \end{equation*}}} \\
        %
        \hline
    \end{tabular}
\end{table*}

\end{document}

This results in the following look. I am attempting to get the left and right cells aligned vertically in the center of the cell. This question dealt with a similar issue, but did not address centering vertically.

enter image description here

2

With the help of baseline=(current bounding box.center), added to the options of the tikzpicture you can get the desired vertically centered alignment:

enter image description here

\documentclass[11pt]{article}

\usepackage{graphicx}
\graphicspath{{images/}}
\pdfminorversion=6
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\pgfplotsset{compat=1.13}
\pgfplotsset{colormap={grays}{gray(0cm)=(0.5);gray(1cm)=(0)}}
\pgfplotsset{samples=3}
\usepackage{amsmath,amssymb}

\begin{document}

\begin{table*}
    \caption{Table Caption}
    \centering
    \begin{tabular}{|c|c|}
        \hline
        \begin{tabular}[c]{@{}c@{}}\includegraphics[width=0.3\linewidth]{example-image} \\
            $p=15$ kN/m \\ $a=5$ m \\ $b=15$ m \\ $c=0$ m \\ $z=$ 2 m \end{tabular} &
        \begin{tikzpicture}[baseline=(current bounding box.center),framed]
            \begin{axis}[%
                view={30}{30},
                width=0.6\linewidth,
                height=3in,
                xlabel={Lateral Distance $x$ [m]},
                xlabel style={align=center, rotate=-7},
                ylabel={Lateral Distance $y$ [m]},
                ylabel style={rotate=27},
                zlabel={Vertical Stress $q_v$ [kPa]}
                ]
                \addplot3[
                patch,
                fill=white,
                opacity=0.8,
                domain=0:20,
                y domain=-5:5
                ]
                {15*2^3/(2*3.1415*(y^2+2^2))*(%
                    ((15-x)*(2*(15-x)^2+3*(y^2+2^2))/((15-x)^2+y^2+2^2)^1.5)-%
                    %
                    ((5-x)*(2*(5-x)^2+3*(y^2+2^2)))/((5-x)^2+y^2+2^2)^1.5))};
                \addlegendentry{$q_v$}
            \end{axis}
        \end{tikzpicture} \\ \hline
        %
        \multicolumn{2}{|c|}{\vbox{%
                \begin{equation*}
                E=mc^2
                \end{equation*}}} \\
        %
        \hline
    \end{tabular}
\end{table*}

\end{document}
3
  • This certainly works, but it doesn't appear to exactly center the content in the left cell. Am I missing a spurious line below the left cell's contents, or is there something else going on here?
    – grfrazee
    Feb 26 '20 at 22:09
  • Very very good code...my compliments.
    – Sebastiano
    Feb 26 '20 at 22:54
  • Wait, I figured out my problem. I had inserted a [t] to top align my second tabular environment without noticing. This is working as intended, now. Thanks very much for your help!
    – grfrazee
    Feb 27 '20 at 19:51

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.