硬编码示例

硬编码示例

我想全局地在嵌入另一个描述列表的描述列表的任何项目的前面添加一个字符。

硬编码示例

字符U+21B3是我能找到的最接近我想要添加的字符的东西。箭头太低了。不幸的是,没有向右的等价物U+21B5 DOWNWARDS ARROW WITH CORNER LEFTWARDS

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\def\defineCMYKcolor(#1,#2,#3,#4)#5{% Just here for item colors
    \pgfmathsetmacro{\myc}{#1/255}%
    \pgfmathsetmacro{\mym}{#2/255}%
    \pgfmathsetmacro{\myy}{#3/255}%
    \pgfmathsetmacro{\myk}{#4/255}%
    \definecolor{#5}{cmyk}{\myc,\mym,\myy,\myk}%
}
\defineCMYKcolor(100,91,7,32){myblue}
\usepackage{fontspec}

\newfontfamily\dejavu[%
  Extension = .ttf
]{DejaVuSerif}

\usepackage{enumitem} % Adds functionality to lists
\setlist[description]{style=nextline,labelwidth=0pt,leftmargin=15pt,font=\normalfont\color{myblue},itemindent=\dimexpr-5pt-\labelsep\relax} % Global Setup Description List

% When a description list is embedded, each item should be prefixed with the character U+21B3
% Unfortunately, there is no right equivalent of U+21B5 DOWNWARDS ARROW WITH CORNER LEFTWARDS, because U+21B3 is actually too low.
% DOWNWARDS ARROW WITH TIP RIGHTWARDS U+21B3
\newcommand\elbowarrowright{\bgroup\dejavu\selectfont \char"21B3\egroup}


\begin{document}
\begin{description}
  \item [apples]
    Really good in apple strudel. Apples come in different varieties:
    \begin{description}
      \item [\elbowarrowright\ Macintosh]% hardcoded
        tart, baking, eating, aromatic
      \item [\elbowarrowright\ Melrose]% hardcoded 
        crisp, sweet, baking, eating
      \item [\elbowarrowright\ Jonathan]% hardcoded
        tart, baking, eating
    \end{description}
  \item [bananas]
    Good with ice cream.
  \item [oranges]
    Sweet delicious fruit.
\end{description}
\end{document}

输出(MikTex)

在此处输入图片描述

答案1

您可以定义仅影响第二级的选项:

\documentclass{article}

\usepackage{xcolor,enumitem} % Adds functionality to lists
\setlist[description]{style=nextline,labelwidth=0pt,leftmargin=15pt,font=\normalfont\color{blue},itemindent=\dimexpr-5pt-\labelsep\relax} %
\setlist[description,2]{font=\normalfont\color{red}\elbowarrowright\ }

\newcommand\elbowarrowright{see~}
\begin{document}
\begin{description}
  \item [apples]
    Really good in apple strudel. Apples come in different varieties:
    \begin{description}
      \item [Macintosh]% hardcoded
        tart, baking, eating, aromatic
      \item [Melrose]% hardcoded
        crisp, sweet, baking, eating
      \item [Jonathan]% hardcoded
        tart, baking, eating
    \end{description}
  \item [bananas]
    Good with ice cream.
  \item [oranges]
    Sweet delicious fruit.
\end{description}
\end{document}

在此处输入图片描述

答案2

作为 Ulrike Fischer 答案的附录,你可以用循环定义大于 2 的所有级别:

TeX 循环

% Loop Sublevels 2 thru 4
\newcount\descriptionlistlevel
\descriptionlistlevel=4
\loop
  \ifnum\descriptionlistlevel>1
    \setlist[description,\descriptionlistlevel]{font=\normalfont\color{blue}\elbowarrowright\ }% Inherit level 1 and override/append to global levels ≥ 2
\advance\descriptionlistlevel by -1
\repeat

代码

enumitem 包提供了以下循环语法:\value{somecounter}+1,但如果您不知道如何进行循环,那么这不会有太大帮助,因此这里有一个示例。

\documentclass{article}
\usepackage{fontspec}
\usepackage{xcolor,enumitem} % Adds functionality to lists
\usepackage{tikz}
% Setup Level 1
\setlist[description]{style=nextline,labelwidth=0pt,leftmargin=15pt,font=\normalfont\color{red},itemindent=\dimexpr-5pt-\labelsep\relax}%Global Level 1
\DeclareRobustCommand\elbowarrowright{\tikz [baseline=-.5ex]\draw [->] (0,1mm) -- (0,0) -- (2mm,0);}
% Loop Sublevels 2 thru 4
\newcount\descriptionlistlevel
\descriptionlistlevel=4
\loop
  \ifnum\descriptionlistlevel>1
    \setlist[description,\descriptionlistlevel]{font=\normalfont\color{blue}\elbowarrowright\ }% Inherit level 1 and override/append to global levels ≥ 2
\advance\descriptionlistlevel by -1
\repeat

\begin{document}
\begin{description}
  \item [apples (Level 1)]
    Really good in apple strudel. Apples come in different varieties:
    \begin{description}
      \item [Macintosh (Level 2)]% hardcoded
        tart, baking, eating, aromatic
        \begin{description}
           \item [Comment (Level 3)]
             This is my favorite apple.
             \begin{description}
               \item [Level 4]
                 For good measure.
                 \begin{description}
                   \item [Level 5]
                     Because I like to know what happens when things do not go as planned. This level inherits only from level 1.
                 \end{description}
             \end{description}
        \end{description}
      \item [Melrose]% hardcoded
        crisp, sweet, baking, eating
      \item [Jonathan]% hardcoded
        tart, baking, eating
    \end{description}
  \item [bananas]
    Good with ice cream.
  \item [oranges]
    Sweet delicious fruit.
\end{description}
\end{document}

输出

在此处输入图片描述

相关内容