![编辑](https://linux22.com/image/469714/%E7%BC%96%E8%BE%91.png)
我正在尝试重现以下有点复杂的支撑图:
我无法按照自己想要的方式进行对齐。理想情况下,类别 A 应位于“更长的文本”和“短项目”分隔的空间的中心,类别 B 应位于最后一列的中心。
目前,我已经通过目测完成了类别标题的对齐,并且我使用该calc
包来测量较长文本的宽度并强制较短的标题占据相同的空间。
但是,这感觉像是一个临时解决方案。有人能想到更好的方法来实现我的目标吗?
这是我的 MWE:
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{calc}
\newcommand{\samesizeas}[2]{\makebox[\widthof{#1}][l]{#2}}
\begin{document}
\begin{align*}
&\samesizeas{$\textsc{longish title}\begin{cases}even longer text\end{cases}$}{}
\hspace*{-35pt}\text{Category A}
\samesizeas{short item}{}\hspace*{8pt}\text{Category B} \\[1em]
&\textsc{longish title}
\begin{cases}
\textit{even longer text}
\begin{cases}
\textit{short item}
\begin{cases}
\textit{item A} \\
\textit{item B that is longer} \\
\textit{item C}
\end{cases} \\
\textit{item that's a lot longer}
\end{cases}
\end{cases} \\
&\samesizeas{\textsc{longish title}}{\textsc{shorter}}
\begin{cases}
\samesizeas{even longer text}{\textit{still short}}
\begin{cases}
\samesizeas{\textit{short item}}{\textit{shorter 1}}
\begin{cases}
\textit{item A} \\
\textit{item B} \\
\textit{item C}
\end{cases} \\
\textit{shorter 2}
\end{cases}
\end{cases}
\end{align*}
\end{document}
答案1
这是一个{NiceTabular}
使用nicematrix
及其\SubMatrix
绘制括号的命令的解决方案。
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\itshape
\begin{NiceTabular}{llll}
\RowStyle{\upshape}
& \Block[c]{}{Category A} && \Block[c]{}{Category B} \\[2mm]
&&& item A \\
\Block{2-1}{\textsc{longish title}}&\Block{2-1}{even longer text}& short item & item B that is longer \\
&&& item C \\
&& \Block[l]{1-2}{item that's a lot longer} \\[2mm]
\Block{4-1}{\textsc{shorter}}& \Block{4-1}{still short}&& item A \\
&& shorter 1 & item B \\
&&& item C \\
&& shorter 2 \\
\CodeAfter
\SubMatrix{\{}{2-2}{5-4}{.}
\SubMatrix{\{}{2-3}{5-4}{.}
\SubMatrix{\{}{2-4}{4-4}{.}
\SubMatrix{\{}{6-2}{9-4}{.}
\SubMatrix{\{}{6-3}{9-4}{.}
\SubMatrix{\{}{6-4}{8-4}{.}
\end{NiceTabular}
\end{document}
您需要多次编译。
答案2
我尝试过使用schemata
它,但我不确定它是否设计了你想要的功能。所以我决定尝试一下forest
间距和calligraphy
花括号/大括号。
% ateb: https://tex.stackexchange.com/a/698199/
\documentclass[12pt]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calligraphy}
\begin{document}
\begin{forest}
for tree={
grow'=0,
tier/.option=level,
child anchor=west,
anchor=child anchor,
fit=band,
},
before typesetting nodes={
where level=1{font=\scshape}{font=\itshape},
},
where n children=0{no edge}{
edge path={%
\noexpand\node (sub-\foresteoption{name}) [fit to=descendants,inner sep=0pt] {};
\noexpand\draw [decorate,decoration={calligraphic brace,amplitude=10pt},ultra thick] (sub-\foresteoption{name}.south west) -- (sub-\foresteoption{name}.north west);
},
before drawing tree={%
if level=0{}{%
tempdima/.max={>O+dO+dw2+d{max y}{y}{#1+#2}}{descendants},
tempdimb/.min={>O+dO+dw2+d{min y}{y}{#1+#2}}{descendants},
tempdima-/.register=tempdimb,
tempdima:=2,
tempdimb+/.register=tempdima,
y/.register=tempdimb,
},
},
},
before computing xy={%
for children={l'=0pt}
}
[,coordinate
[longish title
[even longer text,name=elt
[short item,name=si
[item A]
[item B that is longer,name=bil]
[item C]
]
[item that's a lot longer]
]
]
[shorter
[still short
[shorter 1
[item A]
[item B]
[item C]
]
[shorter 2]
]
]
]
\node (cat a) [fit=(si) (elt)] {};
\node (a) [anchor=base,yshift=10pt] at (cat a.center |- current bounding box.north) {Category A};
\node [anchor=base] at (a.base -| bil.center) {Category B};
\end{forest}
\end{document}
如果需要绘制多个,可以将其转换为可重复使用的样式,以确保一致性并避免重复。如果是一次性的,那显然不相关。如果结构看起来有点间隙,也可以减少叶子之间的距离。
编辑
为了使叶子更紧密地结合在一起,我们可以指定s sep'=0pt
(例如)for tree
。
% ateb: https://tex.stackexchange.com/a/698199/
\documentclass[12pt]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calligraphy}
\begin{document}
\begin{forest}
for tree={
grow'=0,
tier/.option=level,
child anchor=west,
anchor=child anchor,
fit=band,
% adjust the minimum distance between 'children' to draw leaves closer together
s sep'=1pt,
},
before typesetting nodes={
where level=1{font=\scshape}{font=\itshape},
},
where n children=0{no edge}{
edge path={%
\noexpand\node (sub-\foresteoption{name}) [fit to=descendants,inner sep=0pt] {};
\noexpand\draw [decorate,decoration={calligraphic brace,amplitude=10pt},ultra thick] (sub-\foresteoption{name}.south west) -- (sub-\foresteoption{name}.north west);
},
before drawing tree={%
if level=0{}{%
tempdima/.max={>O+dO+dw2+d{max y}{y}{#1+#2}}{descendants},
tempdimb/.min={>O+dO+dw2+d{min y}{y}{#1+#2}}{descendants},
tempdima-/.register=tempdimb,
tempdima:=2,
tempdimb+/.register=tempdima,
y/.register=tempdimb,
},
},
},
before computing xy={%
for children={l'=0pt}
}
[,coordinate
[longish title
[even longer text,name=elt
[short item,name=si
[item A]
[item B that is longer,name=bil]
[item C]
]
[item that's a lot longer]
]
]
[shorter
[still short
[shorter 1
[item A]
[item B]
[item C]
]
[shorter 2]
]
]
]
\node (cat a) [fit=(si) (elt)] {};
\node (a) [anchor=base,yshift=10pt] at (cat a.center |- current bounding box.north) {Category A};
\node [anchor=base] at (a.base -| bil.center) {Category B};
\end{forest}
\end{document}
这可能不太理想。使用 Ti 调整叶子之间的间距并减少叶子内部的填充钾Zinner sep
可能更好。
% ateb: https://tex.stackexchange.com/a/698199/
\documentclass[12pt]{standalone}
\usepackage{forest}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calligraphy}
\begin{document}
\begin{forest}
for tree={
grow'=0,
tier/.option=level,
child anchor=west,
anchor=child anchor,
fit=band,
},
before typesetting nodes={
where level=1{font=\scshape}{font=\itshape},
},
where n children=0{no edge,s sep'=0pt,inner ysep=0pt}{
edge path={%
\noexpand\node (sub-\foresteoption{name}) [fit to=descendants,inner sep=0pt] {};
\noexpand\draw [decorate,decoration={calligraphic brace,amplitude=10pt},ultra thick] (sub-\foresteoption{name}.south west) -- (sub-\foresteoption{name}.north west);
},
before drawing tree={%
if level=0{}{%
tempdima/.max={>O+dO+dw2+d{max y}{y}{#1+#2}}{descendants},
tempdimb/.min={>O+dO+dw2+d{min y}{y}{#1+#2}}{descendants},
tempdima-/.register=tempdimb,
tempdima:=2,
tempdimb+/.register=tempdima,
y/.register=tempdimb,
},
},
},
before computing xy={%
for children={l'=0pt}
}
[,coordinate
[longish title
[even longer text,name=elt
[short item,name=si
[item A]
[item B that is longer,name=bil]
[item C]
]
[item that's a lot longer]
]
]
[shorter
[still short
[shorter 1
[item A]
[item B]
[item C]
]
[shorter 2]
]
]
]
\node (cat a) [fit=(si) (elt)] {};
\node (a) [anchor=base,yshift=10pt] at (cat a.center |- current bounding box.north) {Category A};
\node [anchor=base] at (a.base -| bil.center) {Category B};
\end{forest}
\end{document}