{description} 环境内的多行括号

{description} 环境内的多行括号

环境中可以有多行括号吗description?例如,我希望将下面的三个项目括起来,而无需切换到表格或数组环境。

如果可以的话,那么是否可以嵌套括号?我可以用外括号连接 A 和 C,用内括号连接 B 和 C 吗?

\documentclass{report}

\begin{document}

\begin{description}

\item[A] First one \hfill \\
    Other text

\item[B] Second one \hfill \\
    Other text

\item[C] Second one \hfill \\
    Other text

\end{description}

\end{document}

答案1

其中一种方法是使用\tikzmark标记支架的特定起点和终点,然后使用以下方法绘制支架tikz

在此处输入图片描述

笔记:

  • 对于左括号/花括号的情况,如果您想确保花括号和其他标签与边距对齐,则需要将列表向右移动一点。这可以通过以下包轻松enumitem完成\usepackage{enumitem}

      \begin{description}[leftmargin=!, labelwidth=1.75cm, align=right]
    
  • 对于右侧的括号/花括号,您需要仔细提供\tikzmark文本最右侧部分的 。这样可以计算出将括号放置在右侧多远。如果文本的右侧一直到右边距,则您需要调整linewidth环境的 ,以便有足够的空间容纳括号(和可选文本),或者让括号和可选文本位于边距中。

  • 节点文本是选项,因此如果您不想要,您可以传入一个空参数{}

  • 这确实需要两次运行。第一次确定位置,第二次进行绘图。

  • 来自\tikzmark在正文旁边添加大括号

参考:

代码:

\documentclass{report}

\usepackage{enumitem}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing}

\newcommand{\tikzmark}[1]{%
  \tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {};}

\NewDocumentCommand\LeftBrace{%
    O{}% #1 = draw options
    O{0pt}% #2 = shift to be applied (optional, for use with nested braces)
    m% #3 = top \tikzmark name
    m% #4 = bottom \tikzmark name
    m% #5 = node text
}{%
    \begin{tikzpicture}[overlay,remember picture,baseline]
        \coordinate (Top Start of Bracket)    at ([shift={(#2-12pt,3pt)}]#3.north east);
        \coordinate (Bottom Start of Bracket) at ([shift={(#2-12pt,2pt)}]#4.south east);
        
      \draw[decorate,decoration={brace,raise=6pt, amplitude=1.0ex, mirror}, ultra thick, #1] 
        (Top Start of Bracket) --
             node[xshift=-10pt, align=left, anchor=east, #1] {#5} 
        (Bottom Start of Bracket);
    \end{tikzpicture}    
}
\NewDocumentCommand\RightBrace{%
    O{}% #1 = draw options
    O{0pt}% #2 = shift to be applied (optional, for use with nested braces)
    m% #3 = top \tikzmark name
    m% #4 = bottom \tikzmark name
    m% #5 = right most \tikzmark name
    m% #6 = node text
}{%
    \begin{tikzpicture}[overlay,remember picture,baseline]
        \coordinate (Top Start of Bracket)    at ($(#5)!([yshift=3pt]#3.north)!(#5)$);
        \coordinate (Bottom Start of Bracket) at ($(#5)!([yshift=3pt]#4.south)!(#5)$);
        
        \draw[decorate,decoration={brace,raise=6pt, amplitude=1.0ex, mirror}, ultra thick, #1] 
            ([xshift=#2]Bottom Start of Bracket) --
                node[xshift=10pt, align=left, anchor=west, #1] {#6} 
            ([xshift=#2]Top Start of Bracket);
    \end{tikzpicture}    
}


\newcommand*{\BracektStubSize}{0.5em}%
\NewDocumentCommand\LeftBracket{%
    O{}% #1 = draw options
    O{0pt}% #2 = shift to be applied (optional, for use with nested braces)
    m% #3 = top \tikzmark name
    m% #4 = bottom \tikzmark name
    m% #5 = node text
}{%
    \begin{tikzpicture}[overlay,remember picture,baseline]
        \coordinate (Top Start of Bracket) at ([shift={(#2-15pt,5pt)}]#3.north east);
        \coordinate (Bottom Start of Bracket) at ([shift={(#2-15pt,2pt)}]#4.south east);
        \draw[ultra thick, #1] 
            (Top Start of Bracket) --++(-\BracektStubSize,0) 
                |-(Bottom Start of Bracket) ;
            
        \node[xshift=-5pt, align=left, anchor=east, #1]
            at ($(Bottom Start of Bracket)!0.5!(Top Start of Bracket)$) {#5};
    \end{tikzpicture}    
}
\NewDocumentCommand\RightBracket{%
    O{}% #1 = draw options
    O{0pt}% #2 = shift to be applied (optional, for use with nested braces)
    m% #3 = top \tikzmark name
    m% #4 = bottom \tikzmark name
    m% #5 = right most \tikzmark name
    m% #6 = node text
}{%
    \begin{tikzpicture}[overlay,remember picture,baseline]
        \coordinate (Top Start of Bracket)    at ($(#5)!([yshift=3pt]#3.north)!(#5)$);
        \coordinate (Bottom Start of Bracket) at ($(#5)!([yshift=3pt]#4.south)!(#5)$);
        
        \draw[ultra thick, #1] 
            ([xshift=#2]Bottom Start of Bracket) -- ++(\BracektStubSize,0) 
            |- ([xshift=#2]Top Start of Bracket) ;
            
        \node[xshift=10pt, align=left, anchor=west, #1]
            at ($(Bottom Start of Bracket)!0.5!(Top Start of Bracket)$) 
            {#6};
    \end{tikzpicture}    
}

\SetLabelAlign{parright}{\strut\smash{\parbox[t]{\labelwidth}{\raggedleft#1}}}
\begin{document}

\begin{description}[leftmargin=!, labelwidth=1.75cm, align=right]
\item[A] \tikzmark{Mark A}First one \hfill \\
    Other text

\item[B] \tikzmark{Mark B}Second longer one\tikzmark{Right Most Node}\hfill \\
    Other text

\item[C] \tikzmark{Mark C}Second one \hfill \\
    Other text
\end{description}
\LeftBracket[blue][-7pt]{Mark A}{Mark C}{ABC}
\LeftBracket[red]{Mark B}{Mark C}{}
\RightBracket[violet][7pt]{Mark A}{Mark C}{Right Most Node}{EFG}
\RightBracket[olive]{Mark B}{Mark C}{Right Most Node}{}

\begin{description}[leftmargin=!, labelwidth=1.75cm, align=right]
\item[A] \tikzmark{Mark A}First one \hfill \\
    Other text

\item[B] \tikzmark{Mark B}Second longer one\tikzmark{Right Most Node}\hfill \\
    Other text

\item[C] \tikzmark{Mark C}Second one \hfill \\
    Other text
\end{description}
\LeftBrace[magenta][-7pt]{Mark A}{Mark C}{UVW}
\LeftBrace[cyan]{Mark B}{Mark C}{}
\RightBrace[orange][7pt]{Mark A}{Mark C}{Right Most Node}{XYZ}
\RightBrace[olive]{Mark B}{Mark C}{Right Most Node}{}
\end{document}

相关内容