这是我之前问题的后续这里和这里。简而言之,我想要实现的是多列的圆弧,我正在使用 Tikz 实现。代码如下所示。
\documentclass[12pt]{article}
\usepackage{tikz}
\newcommand{\mulcol}[1]{\multicolumn{2}{c}{#1}}
\usetikzlibrary{decorations.pathmorphing}
\newcommand\myarc[2][]{%
\tikz[overlay,remember picture] \node at (0,0.4) (a) {};#2%
\tikz[overlay,remember picture] \node at (0,0.4) (b) {};
\begin{tikzpicture}[overlay,remember picture,out=35,in=145,distance=0.2cm]
\draw[#1] (a.center) to (b.center);
\end{tikzpicture}}
\begin{document}
\begin{center}
\begin{tabular}{*{6}{c}}
\myarc{a&a}&a&a&a&a\\
\myarc{\mulcol{a}}&\mulcol{a}&\mulcol{a}\\
\end{tabular}
\end{center}
\end{document}
产出量:
这样,第一行可以正确显示内容和上方的弧线,但第二行会使多列的内容向前偏移(图中用红色圆圈标记)。是什么原因导致出现这种偏移?有什么方法可以纠正它吗?
答案1
正如评论中提到的,这\multicolumn
必须是单元格中的第一件事。此解决方案切换myarc
并mulcol
添加\hfill
以填充宽度。
代码
\documentclass[12pt]{article}
\usepackage{tikz}
\newcommand{\mulcol}[1]{\multicolumn{2}{c}{#1}}
\newcommand{\mulcols}[1]{\multicolumn{3}{c}{#1}} % newly added command
\usetikzlibrary{decorations.pathmorphing}
\newcommand\myarc[2][]{%
\tikz[overlay,remember picture] \node at (0,0.4) (a) {};#2%
\tikz[overlay,remember picture] \node at (0,0.4) (b) {};
\begin{tikzpicture}[overlay,remember picture,out=35,in=145,distance=0.2cm]
\draw[#1] (a.center) to (b.center);
\end{tikzpicture}}
\begin{document}
Case for multicolumn 2
\begin{center}
\begin{tabular}{*{6}{c}}
\myarc{a&a}&a&a&a&a\\[2pt]
\mulcols{\myarc{\hfill a\hfill}}&\mulcol{a}&\mulcol{a}\\
\end{tabular}
\end{center}