我对此解决方案有疑问邮政如果我不想使用粗体文本。
我按照下面所述更改了代码。但是项目的文本(例如 Animal1:)现在位于文档的左边距(我希望它像文档的正常文本一样位于左边距)。我不知道为什么会发生这种情况,因为使用粗体文本时它可以正常工作。如果有人有想法就好了。
% arara: pdflatex
\documentclass{scrbook}
\usepackage{calc}
\makeatletter
\newcommand{\DESCRIPTION@original@item}{}
\let\DESCRIPTION@original@item\item
\newcommand*{\DESCRIPTION@envir}{DESCRIPTION}
\newlength{\DESCRIPTION@totalleftmargin}
\newlength{\DESCRIPTION@linewidth}
\newcommand{\DESCRIPTION@makelabel}[1]{\llap{#1}}%
\newcommand{\DESCRIPTION@item}[1][]{%
\setlength{\@totalleftmargin}%
{\DESCRIPTION@totalleftmargin+\widthof{#1}-\leftmargin}%
\setlength{\linewidth}
{\DESCRIPTION@linewidth-\widthof{#1}+\leftmargin}%
\par\parshape \@ne \@totalleftmargin \linewidth
\DESCRIPTION@original@item[#1]%
}
\newenvironment{DESCRIPTION}
{\list{}{\setlength{\labelwidth}{0cm}%
\let\makelabel\DESCRIPTION@makelabel}%
\setlength{\DESCRIPTION@totalleftmargin}{\@totalleftmargin}%
\setlength{\DESCRIPTION@linewidth}{\linewidth}%
\renewcommand{\item}{\ifx\@currenvir\DESCRIPTION@envir
\expandafter\DESCRIPTION@item
\else
\expandafter\DESCRIPTION@original@item
\fi}}
{\endlist}
\makeatother
\usepackage{blindtext}
\begin{document}
\begin{DESCRIPTION}
\blindtext
\item[Animal1:] \textbf{Lion}\\
A lion is ... \blindtext
\item[Animal2:] \textbf{Elephant}\\
An elephant is ...
\end{DESCRIPTION}
\end{document}
答案1
这里的环境labeling
可能会有帮助。
% arara: pdflatex
\documentclass{scrbook}
\usepackage{scrbase}
\usepackage{blindtext}
\usepackage{showframe}
\newcommand{\animalname}[1]{#1}
%\setkomafont{labelinglabel}{\bfseries}%if you want it bold
%\renewcommand{\animalname}{\textbf}
\begin{document}
\begin{labeling}[:]{longest animal}% the optional argument sets a separator
% the obligatory argument takes the longest expression
\item[long Animal1] \animalname{Wombat}\\
A lion is ... \blindtext
\item[Animal2] \animalname{Capybara}\\
An elephant is ...
\blindtext
\item[long Animal2] \animalname{Nasenb\"ar}\\
An elephant is ...
\blindtext
\end{labeling}
\end{document}