我想创建以下表格,其中有“跨越”\hline
表格行之间的圆圈。我不确定该怎么做。我还想在圆圈中输入数字。这应该是 tikzpicture 而不是表格吗?我真的不知道从哪里开始。
以下是我的想法。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\begin{document}
Multiply input by 4 and add 3
\begin{center}
\begin{tabular}{ |c|c|c|c| }
\hline
col1 & Input & Output \\
\hline
\multirow{3}{4em}{Multiple row} & 1 & 7 \\
& 2 & 11 & Gap of "4" between rows in a circle\\
& 3 & 15 \\
\hline
\end{tabular}
\end{center}
\end{document}
我想我是在问如何做到这一点。matrix
有人建议使用 Tikz。
我也在使用 Overleaf,所以正如所建议的那样,我不得不使用 & 符号替换。
答案1
以下是一个matrix
模拟c
列的样式eqparbox
。样式center align per column
(大致)取自这里。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{eqparbox}
\newbox\matrixcellbox
\tikzset{center align per column/.style={column #1/.style={nodes={execute at begin
node={\setbox\matrixcellbox=\hbox\bgroup\strut},
execute at end
node={\egroup\eqmakebox[\tikzmatrixname\the\pgfmatrixcurrentcolumn][c]{\copy\matrixcellbox}}}}},
}
\begin{document}
Multiply input by 4 and add 3
\begin{center}
\begin{tikzpicture}
\matrix[matrix of nodes,inner sep=0pt,outer sep=0pt,
nodes={draw,inner sep=2pt,font=\sffamily,inner xsep=1ex},
column sep=-\pgflinewidth/2,row sep=-\pgflinewidth/2,
center align per column/.list={1,2}] (mat) {
Input & Output\\
1 & 7 \\
2 & 11 \\
3 & 15 \\
};
\path[nodes={circle,anchor=west,inner sep=1ex,draw,semithick,midway}]
(mat-2-2.south-|mat.east) -- (mat-3-2.north-|mat.east) node{}
(mat-3-2.south-|mat.east) -- (mat-4-2.north-|mat.east) node{};
\end{tikzpicture}
\end{center}
\end{document}
或者用于ampersand replacement
投影机等等。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{eqparbox}
\newbox\matrixcellbox
\tikzset{center align per column/.style={column #1/.style={nodes={execute at begin
node={\setbox\matrixcellbox=\hbox\bgroup\strut},
execute at end
node={\egroup\eqmakebox[\tikzmatrixname\the\pgfmatrixcurrentcolumn][c]{\copy\matrixcellbox}}}}},
}
\begin{document}
Multiply input by 4 and add 3
\begin{center}
\begin{tikzpicture}
\matrix[matrix of nodes,inner sep=0pt,outer sep=0pt,
nodes={draw,inner sep=2pt,font=\sffamily,inner xsep=1ex},
column sep=-\pgflinewidth/2,row sep=-\pgflinewidth/2,
center align per column/.list={1,2},
ampersand replacement=\&] (mat) {
Input \& Output\\
1 \& 7 \\
2 \& 11 \\
3 \& 15 \\
};
\path[nodes={circle,anchor=west,inner sep=1ex,draw,semithick,midway}]
(mat-2-2.south-|mat.east) -- (mat-3-2.north-|mat.east) node{}
(mat-3-2.south-|mat.east) -- (mat-4-2.north-|mat.east) node{};
\end{tikzpicture}
\end{center}
\end{document}
答案2
你可以这样做nicematrix
:
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\renewcommand{\arraystretch}{1.6}
$\begin{NiceMatrix}[hvlines]
\text{Input} & \text{Ouput} \\
1 & 7 \\
2 & \\
3 &
\CodeAfter
\tikz \draw ([xshift=3mm]3-|3) circle (3mm) ([xshift=3mm]4-|3) circle (3mm) ;
\end{NiceMatrix}$
\end{document}