Longtable,包含 tikz、padding、自定义列和对齐问题

Longtable,包含 tikz、padding、自定义列和对齐问题

我的白鲸。我无论如何也想不通列定义中存在的 minipage 导致的边距是怎么回事。

给定列类型M扩展c:我可以将第 6 行从 更改为>{>{%然后左侧填充突然消失,而右侧填充保持不变。如果我%在第 14 行末尾(迷你页面结束处)添加 ,则右侧填充也会消失。注释不是这样工作的……此外,tikz 在迷你页面中没有垂直对齐,我以为我已经处理了这个问题\begin{minipage}[c]{#1}

我可以将第 11 行从 更改cm{#1}现在第 6 行和第 14 行%没有任何效果...并且 tikz 仍然没有垂直居中(存在顶部缩进)。如果我手动将 minipage 设置为 tikzpicture 中的高度 30pt,那么顶部会有一个很大的边距。然后,如果我手动将 minipage 高度设置为 34pt,tikzpicture 将在 minipage 上垂直和水平居中...

但是,这并不能解决我的问题,即如何让 minipage 自动调整其相对于其他任何表格上的内容的高度,或者如何忽略顶部的最小填充。我似乎也无法将高度转换为传递给列类型的第二个变量M,这也没有帮助。

如果我将列设置为 67.5pt,则第一个 tikz 上会出现“hbox 太宽”的提示。但是,tikz 的宽度应该是 (15+37.5+15=67.5) 点。棕色框的溢出显示 minipage 似乎也有自己的边距。

tikzpicture 选项仅用于试验如何解决此对齐问题。

我想要的只是完美居中的 tikz 和完美居中的数学,并将单个最小边距均匀应用于所有 8 个单元格。如果可以自动化,那就更好了。这似乎超出了我现在的知识水平……而且完全不合理,以至于它可以/已经变得如此复杂

\documentclass{article}
\usepackage{array,longtable,tikz,calc}
\setlength{\tabcolsep}{0mm}
\newcolumntype{M}[1]
{
    >{
            \noindent\begin{minipage}[c][][c]{#1}%\textwidth-1.5\arrayrulewidth-2\tabcolsep}
            %\vspace{0pt}
            \centering
     }
    c
    <{
        %\vspace{0pt}
         \end{minipage}
     }
}
\newcolumntype{A}[1]
{%
>{$}
    r
<{$}
@{\extracolsep{0pt}}
>{${}}
    l
<{$}
|}%
\begin{document}
\begin{longtable}{| M{68.5pt} | A |}% \setstretch{1.0}%q{0.38} |}
\hline
    \noindent\begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}]%  ,baseline=(current bounding box.center)]
        \draw [gray] (0,0) circle (15pt);
        \filldraw [gray] (0,0) circle (1pt);
        \draw [gray] (37.5pt,0) circle (15pt);
        \filldraw [gray] (37.5pt,0) circle (1pt);
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & \underline{2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)}  &\geq  2r_f + R_1 r_f 
    \tabularnewline
\hline
    \centering\begin{tikzpicture}[baseline=(current bounding box.south)]%[every node/.style={inner sep=0,outer sep=0}]
        \draw [gray] (0,0) circle (15pt);
        \filldraw [gray] (0,0) circle (1pt);
        \draw [gray] (30pt,0) circle (15pt);
        \filldraw [gray] (30pt,0) circle (1pt);
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &\leq   2r_f+\underline{R_1 r_f} \tabularnewline
\hline
    \begin{tikzpicture} [baseline=(current bounding box.center)]
        \draw [gray] (0,0) circle (15pt);
        \filldraw [gray] (0,0) circle (1pt);
        \draw [gray] (22.5pt,0) circle (15pt);
        \filldraw [gray] (22.5pt,0) circle (1pt);
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &<   \underline{2r_f}+R_1 r_f \tabularnewline
\hline
    \begin{tikzpicture} %[baseline=(current bounding box.center)]
        \draw [gray] (0,0) circle (15pt);
        \filldraw [gray] (0,0) circle (1pt);
        \draw [gray] (11.25pt,0) circle (15pt);
        \filldraw [gray] (11.25pt,0) circle (1pt);
        \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left( ^{\pi} \!/ _{n_k} \right)  &<   \underline{2r_f}+R_1 r_f \tabularnewline
\hline
\end{longtable}
\end{document}

答案1

我必须承认,我不太理解你的问题。不清楚为什么你要longtable对所用的列类型使用如此复杂的定义。我怀疑你正在寻找这样的东西:

在此处输入图片描述

上表的代码很简单(我留longtable在里面):

\documentclass[12pt]{article}
\usepackage{array, makecell, longtable}
\setcellgapes{5pt}
\usepackage{tikz}
\usepackage{xfrac}

\begin{document}
\begingroup
\makegapedcells
\tikzset{every node/.style={inner sep=0,outer sep=0}}
\begin{longtable}{| c | >{$\displaystyle}c<{$} |}
    \hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (37.5pt,0) circle (15pt);
    \filldraw [gray]    (37.5pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & \underline{2r_c \sin \left(\sfrac{\pi}{n_k}\right)} \geq  2r_f + R_1 r_f  \tabularnewline
    \hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (30pt,0) circle (15pt);
    \filldraw [gray]    (30pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) \leq  2r_f+\underline{R_1 r_f}    \tabularnewline
    \hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (22.5pt,0) circle (15pt);
    \filldraw [gray]    (22.5pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) < \underline{2r_f}+R_1 r_f        \tabularnewline
    \hline
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (11.25pt,0) circle (15pt);
    \filldraw [gray]    (11.25pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) <  \underline{2r_f + R_1 r_f}     \tabularnewline
    \hline
\end{longtable}
\endgroup
\end{document}

编辑:

在您发表评论之后,您的问题更加清楚了:

  • longtable通常在表格太长而无法容纳一页时使用。它使表格可以在下一页继续显示
  • 并且(和)\begingroup\endgroup设置仅对此表有效。\longtable\makegapedcells\tikzset{every node/.style={inner sep=0,outer sep=0}}
  • 因为\tikzset{...}是之前\longtable,所以它对所有tikz图片都有效\longtable
  • 表格和图像通常分别放在浮动环境中tablefigure。这些浮动对象可以在文本中移动(浮动)。这意味着它们在文本中的确切位置由算法确定latex,该算法几乎可以确保文档获得最佳外观。它还可以包含仅对此浮动对象有效的设置(请参阅姆韦以下)
  • 单元格内容的水平位置取决于列的类型(对于可以包含“一段”文本的单元格c,标准为lr分别表示居中、左对齐和右对齐)p{...}
  • 垂直位置取决于单元格内容的基线。图像的默认基线位置在其底部。
  • 的基线位置tikzpicture可以通过选项更改baselinebaseline=(current bounding box.base)将移动到图像的垂直中心。将baseline=-3pt图像的垂直中心修剪到单元格行基线以下 3pt 处
  • 为了更好地查看数学表达式,我添加了包xfrac并使用其\sfrac宏在正弦函数参数中输入分数。
  • \makegapedcells包中的命令makcell添加由\setcellgapes{<length>}单元格内容上方和下方的宏决定的垂直空间

考虑到上述情况,mwe 为:

\documentclass[12pt]{article}
\usepackage{array, makecell}  % <--- changed
\setcellgapes{5pt}
\usepackage{tikz}
\usepackage{xfrac}

\begin{document}
    \begin{table}[htb]             % <--- added
\makegapedcells
\tikzset{every node/.style={inner sep=0,outer sep=0}}
\begin{tabular}{| c | >{$}c<{$} |} % <--- changed
    \hline
\begin{tikzpicture}[baseline=-3pt]  % <--- changed
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (37.5pt,0) circle (15pt);
    \filldraw [gray]    (37.5pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & \underline{2r_c \sin \left(\sfrac{\pi}{n_k}\right)} \geq  2r_f + R_1 r_f  \tabularnewline
    \hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (30pt,0) circle (15pt);
    \filldraw [gray]    (30pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) \leq  2r_f+\underline{R_1 r_f}    \tabularnewline
    \hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (22.5pt,0) circle (15pt);
    \filldraw [gray]    (22.5pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) < \underline{2r_f}+R_1 r_f        \tabularnewline
    \hline
\begin{tikzpicture}[baseline=-3pt] % <--- changed
    \draw [gray]        (0,0) circle (15pt);
    \filldraw [gray]    (0,0) circle (1pt);
    \draw [gray]        (11.25pt,0) circle (15pt);
    \filldraw [gray]    (11.25pt,0) circle (1pt);
    \draw [brown] (current bounding box.south west) rectangle (current bounding box.north east);
    \end{tikzpicture}
    & 2r_c \sin \left(\sfrac{\pi}{n_k}\right) <  \underline{2r_f + R_1 r_f}     \tabularnewline
    \hline
\end{tabular}                % <--- added
    \end{table}              % <--- changed
\end{document}

结果是:

在此处输入图片描述

相关内容