1

I have some fairly specific requirements. I'm trying to draw a "table" (in quotes because I don't necessarily care if I use the tabular environment) with captions (text) on the left, and associated content on the right. The "content" is tikz graphs and (in the last row) a code listing.

Here is what I have right now:

\begin{figure}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}
\begin{tabularx}{\textwidth}{X X}
    \\[0.5em]
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &  \\[0.5em]

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &

\begin{tikzpicture}[framed]
    \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}}
    \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) {lorem};
\end{tikzpicture}

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &

\begin{tikzpicture}[framed]
    \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}}
    \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) at (0, 0) {lorem};
    \node[vertex] (b) at (-1, 1) {ipsum};
    \node[vertex] (c) at (1, 1) {dolor};

    \draw[edge] (b) to (a);
    \draw[edge] (c) to (a);
\end{tikzpicture}

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &

\begin{tikzpicture}[framed]
    \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}}
    \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) at (0, 0) {lorem};
    \node[vertex] (b) at (-1, 1) {ipsum};
    \node[vertex] (c) at (1, 1) {dolor};
    \node[vertex] (d) at (-1, 2) {sit};

    \draw[edge] (b) to (a);
    \draw[edge] (c) to (a);
    \draw[edge] (d) to (b);
\end{tikzpicture}

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &

\begin{tikzpicture}[framed]
    \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}}
    \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) at (0, 0) {lorem};
    \node[vertex] (b) at (-1, 1) {ipsum};
    \node[vertex] (c) at (1, 1) {dolor};
    \node[vertex] (d) at (-1, 2) {sit};
    \node[vertex] (e) at (1, 2) {amet};

    \draw[edge] (b) to (a);
    \draw[edge] (c) to (a);
    \draw[edge] (d) to (b);
    \draw[edge] (e) to (c);
\end{tikzpicture}

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. & 
\begin{tikzpicture}[framed]
    \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}}
    \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) at (0, 0) {lorem};
    \node[vertex] (b) at (-1, 1) {ipsum};
    \node[vertex] (c) at (1, 1) {dolor};
    \node[vertex] (d) at (-1, 2) {sit};
    \node[vertex] (e) at (1, 2) {amet};
    \node[vertex] (f) at (1, 3) {consectetur};

    \draw[edge] (b) to (a);
    \draw[edge] (c) to (a);
    \draw[edge] (d) to (b);
    \draw[edge] (e) to (c);
    \draw[edge] (f) to (e);
\end{tikzpicture}
\\

\\[0.5em]
\hline

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. &
\begin{lstlisting}^^J
Lorem ipsum = Dolor.sit();^^J
Amet consectetur = adipiscing(elit);^^J
sed.do(eiusmod);^^J
^^J
\end{lstlisting}

\end{tabularx} \end{figure}

The problem is, this renders like this:

enter image description here

The main problem here is that the content on the right isn't aligned with the caption on the left. The \hlines and the frames around the graphs are just here to illustrate, I don't want them in the final product, so it's hard to tell what goes with what, not to mention the table is much taller than it needs to be. It seems like the problem is that the captions aren't aligning to the top of their row.

How can I get what I'm looking for? My requirements are:

  1. Align caption and content in sensible way, ideally vertical center to vertical center.
  2. Use tikz for the graphs.
  3. The code block in the last row should look like code, i.e. be in monospaced font.
  4. The whole thing is inside a figure.

Beyond that, I don't mind what libraries or environments I use.

Jack M
  • 146
  • The contents of the cells are aligned at their baseline. For text, this is (in this case for X) the baseline of the first row. For the Tikzpicture, it is the bottom of the bounding box/the picture. You can use the baseline option to set this to any y value or to the y value of a coordinate/anchor. For TikZ baseline=(current bounding box.center) centers the picture vertically. – Qrrbrbirlbel Nov 02 '22 at 16:44
  • The vertical alignment of a X column can be changed, too. (See the manual.) This question seems related. – Qrrbrbirlbel Nov 02 '22 at 16:48

1 Answers1

1

Something to start with. Instead of tabular, you can use sidebyside tcolorboxes. One for each pair of text+tikzfigure, you can select the width for each part or left the package to do it for you. About the listing part, you can use a tcblisting box with comment and listing type.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{arrows}

\begin{document}

\begin{figure} \caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}

\tcbsidebyside[blanker, sidebyside gap = 5mm, halign lower=center]{ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. }{}

\tcbsidebyside[blanker, sidebyside gap = 5mm, halign lower=center]{ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. }{ \begin{tikzpicture} \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}} \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) {lorem};
\end{tikzpicture}

}

\tcbsidebyside[blanker, sidebyside gap = 5mm, halign lower=center, sidebyside adapt=right]{ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. }{ \begin{tikzpicture} \tikzset{vertex/.style = {shape=rectangle,draw,font=\footnotesize}} \tikzset{edge/.style = {->,> = latex'}}

    \node[vertex] (a) at (0, 0) {lorem};
    \node[vertex] (b) at (-1, 1) {ipsum};
    \node[vertex] (c) at (1, 1) {dolor};

    \draw[edge] (b) to (a);
    \draw[edge] (c) to (a);
\end{tikzpicture}

}

\begin{tcblisting}{blanker, comment side listing, comment={Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}, righthand width=0.6\linewidth } Lorem ipsum = Dolor.sit(); Amet consectetur = adipiscing(elit); sed.do(eiusmod); \end{tcblisting} \end{figure} \end{document}

enter image description here

Ignasi
  • 136,588
  • This seems to work really well. Do you have any recommendations for how to put a monospace font code block at the bottom? – Jack M Nov 02 '22 at 16:45
  • @JackM I've updated the answer with a listing example. If you decide to go with this solution, please take a look at tcolorbox documentation. It offers a lot of options to customize the output. – Ignasi Nov 03 '22 at 10:41