我有以下表格代码
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{tabularx}
\usepackage{multirow}
\begin{document}
{\def\arraystretch{1.5}\tabcolsep=10pt \large
\begin{tabularx}{\textwidth}{Xl}
\multirow{2}{*}{\scalebox{1.5}{$\square$ Modul 1}}& Exercise 1\\
&Exercise 2\\
\multirow{4}{*}{\scalebox{1.5}{$\square$ Modul 2}}& Exercise 3\\
&Exercise 4\\
&Exercise 5\\
&Exercise 6\\
\multirow{2}{*}{\scalebox{1.5}{$\square$ Modul 3}}& Exercise 7\\
&Exercise 8\\
\end{tabularx}
}
\end{document}
但我想添加一些线条让它看起来像这样(我用 Gimp 画了线条):
我怎样才能实现这个目标?
答案1
{NiceTabular}
这是的解决方案。使用 ,使用在数组的单元格、行和列下nicematrix
创建的 PGF/Tikz 节点,用 Tikz 绘制线条。nicematrix
\documentclass[12pt,a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{nicematrix}
\usepackage{tikz}
\begin{document}
{
\renewcommand{\arraystretch}{1.5}
\large
\begin{NiceTabular}{cw{c}{4cm}l}
\Block[name=modul1]{2-1}{$\square$ Modul 1}
&& Exercise 1\\
&& Exercise 2\\
\Block[name=modul2]{4-1}{$\square$ Modul 2}
&& Exercise 3\\
&& Exercise 4\\
&& Exercise 5\\
&& Exercise 6\\
\Block[name=modul3]{2-1}{$\square$ Modul 3}
&& Exercise 7\\
&& Exercise 8\\
\CodeAfter
\begin{tikzpicture}
\draw [dotted,thick]
(modul1.east) -- ++(3cm,0) |- (1-|last)
(modul1.east) -- ++(3cm,0) |- ([yshift=0.5mm]5-|last) ;
\draw
(modul2.east) -- ++(1cm,0) |- (3-|last)
(modul2.east) -- ++(1cm,0) |- (7-|last) ;
\draw [dashed]
(modul3.east) -- ++(3cm,0) |- ([yshift=-0.5mm]5-|last)
(modul3.east) -- ++(3cm,0) |- (9-|last) ;
\end{tikzpicture}
\end{NiceTabular}
}
\end{document}
您需要多次编译(因为 PGF/Tikz 节点)。