绘制一个“表格”,左侧有标题,右侧有混合内容(tikz 和代码列表)

绘制一个“表格”,左侧有标题,右侧有混合内容(tikz 和代码列表)

我有一些相当具体的要求。我试图绘制一个“表格”(之所以用引号是因为我不介意是否使用该tabular环境),左侧是标题(文本),右侧是相关内容。“内容”是tikz图表和(最后一行)代码列表。

以下是我现在拥有的:

\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}

问题是,渲染结果如下:

在此处输入图片描述

这里的主要问题是右侧的内容与左侧的标题不对齐。\hline图表周围的 s 和框架只是为了说明,我不希望它们出现在最终产品中,所以很难说清楚什么与什么相配,更不用说表格比它需要的高度要高得多。问题似乎是标题没有与行的顶部对齐。

我怎样才能得到我想要的东西?我的要求是:

  1. 以合理的方式对齐标题和内容,理想情况下是垂直中心到垂直中心。
  2. 用于tikz图表。
  3. 最后一行的代码块应该看起来像代码,即等宽字体。
  4. 整个东西都在里面figure

除此之外,我不介意使用什么库或环境。

答案1

开始吧。除了tabular,您可以使用sidebysidetcolorboxes。每对文本+tikzfigure 一个,您可以为每个部分选择宽度,或者让包为您完成。关于部分listing,您可以使用tcblisting带有类型的框comment and listing

\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}

在此处输入图片描述

相关内容