另一种看法

另一种看法

适用以下条件:

  1. 每列宽度不得超过 25 毫米
  2. 一列较窄的行必须扩展到同一列的最宽行(如果最宽行小于 25 毫米,则不能扩展到 25 毫米)

请注意,在节点内使用varwidth环境tikz会在该节点的右侧创建额外的空间(我无法删除,也许你会删除),并且与text width使用时相比,文本换行效果更差。但text width会将节点从一开始就扩展到 25 毫米,即使其中的文本宽度小于 25 毫米。

作为奖励,最好减少节点边框在它们彼此接触的地方的厚度,以便表格的边框(作为一个整体)在其厚度上看起来均匀(并且在某些地方与其他地方相比看起来不会更明确)。

\documentclass{standalone}
\usepackage{tikz}
\tikzset
  { every node/.style=
      { anchor=north west
      }
  }
\begin{document}
  \begin{tikzpicture}
    % 25mm ruler
    \path[draw=red,line width=1pt](0,0)--(25mm,0);

    % should span two columns
    \path node[draw](h)
      { header/title
      };

    \path node[draw](r1c1)at(h.south west)
      { row 1, col 1 (abcd)
      };

    \path node[draw](r1c2)at(r1c1.north east)
      { row 1, col 2 (abcdefg)
      };

    % width should match that of row 1, col 1
    %  (because row 1, col 1 is wider)
    \path node[draw](r2c1)at(r1c1.south west)
      { row 2, col 1
      };

    % width should match that of row 1, col 2
    %  (because row 1, col 2 is wider)
    \path node[draw](r2c2)at(r2c1.north east)
      { row 2, col 2 (ab)
      };
  \end{tikzpicture}
\end{document}

另一种看法

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset
  { every node/.style=
      { anchor=north west
      }
  }
\begin{document}
  \begin{tikzpicture}
    % should span two columns
    \path node[draw](h)
      { header/title
      };

    \path node
      [ draw,
        anchor=north east
      ](r1c1)at(h.south)
      { row 1, col 1 (abcd)
      };

    \path node[draw](r1c2)at(r1c1.north east)
      { row 1, col 2 (abcdefg)
      };

    % width should match that of row 1, col 1
    %  (because row 1, col 1 is wider)
    \path node
      [ draw,
        anchor=north east
      ](r2c1)at(r1c1.south east)
      { row 2, col 1
      };

    % width should match that of row 1, col 2
    %  (because row 1, col 2 is wider)
    \path node[draw](r2c2)at(r2c1.north east)
      { row 2, col 2 (ab)
      };

    % 25mm ruler
    \path[draw=red,line width=1pt](r1c1.north east)--($(r1c1.north east)+(25mm,0)$);

  \end{tikzpicture}
\end{document}

答案1

这是否朝着正确的方向发展?如果不是,我很乐意将其删除。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,nodes={inner sep=2pt},
column 1/.style={nodes={align=right,anchor=east}},
column 2/.style={nodes={align=left,anchor=west}},
column sep=-\pgflinewidth,row
sep=-\pgflinewidth,outer sep=0pt,inner sep=0pt,draw] (mat){
row 1, col 1 (abcd) & row 1, col 2 (abcdefg)\\
row 2, col 1 & row 2, col 2 (ab)\\
};
\draw ($(mat-1-1.south)!0.5!(mat-2-1.north)$) coordinate(aux1)
 ($(mat-1-1.east)!0.5!(mat-1-2.west)$) coordinate(aux2)
 (mat.west|-aux1) -- (mat.east|-aux1)
  (mat.north-|aux2) -- (mat.south-|aux2);
    \path node[draw,anchor=south,outer sep=0pt](h) at (mat.north-|aux2)
      { header/title
      };

    % 25mm ruler
    \path[draw=red,line width=1pt](mat-1-1.north east)--
    ($(mat-1-1.north east)+(25mm,0)$);

  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容