我尝试将一些文本与 itemize-list 的项目符号对齐。如何正确执行此操作?
我找到了一个解决方法,但效果很差。有没有更好的方法?也许是一个具有精确项目符号缩进的变量?
谢谢 :)
以下是 MWE:
\documentclass[a4paper, 12pt, parskip]{scrreprt}
\begin{document}
This is a normal text that should be left aligned.
\mbox{\hspace{16.5pt}This} is another text over multiple lines that I want to have aligned equally to the\\
\mbox{\hspace{16.5pt}bullets} of the following list:
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\end{document}
答案1
常规列表的奇怪之处在于其标签或设置右对齐。以下indentitem
环境模拟了这种方法,缩进到项目内容的正确位置,然后后退宽度\textbullet
。
\documentclass[a4paper,12pt,parskip]{scrreprt}
\usepackage{changepage}
\makeatletter
\newenvironment{indentitem}{%
\sbox\@tempboxa{\textbullet}%
\begin{adjustwidth}{\dimexpr\itemindent+\labelwidth-\wd\@tempboxa}{0pt}%
}{%
\end{adjustwidth}%
}
\makeatother
\begin{document}
This is a normal text that should be left aligned.
\mbox{\hspace{16.5pt}This} is another text over multiple lines that I want to have aligned equally to the \\
\mbox{\hspace{16.5pt}bullets} of the following list:
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\noindent\hrulefill
This is a normal text that should be left aligned.
\begin{adjustwidth}{16.5pt}{0pt}
This is another text over multiple lines that I want to have aligned equally to the
bullets of the following list:
\end{adjustwidth}
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\noindent\hrulefill
This is a normal text that should be left aligned.
\begin{indentitem}
This is another text over multiple lines that I want to have aligned equally to the
bullets of the following list:
\end{indentitem}
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\end{document}
答案2
这是一个基于的解决方案是否可以使用不带嵌套列表的 \itemize 为 \subitems 创建项目符号? 。
每当你想要文本按你显示的方式对齐时,请使用\SubItem
而不是通常的\item
。然后
This is a normal text that should be left aligned.
\begin{itemize}
\item normal list text
\SubItem This is second text over multiple lines that I want to have aligned
equally to the to the following list
\item This is item 1.
\SubItem This is third text over multiple lines that I want to have aligned
equally to the to the following list
\item And this is a second item.
\end{itemize}
生产
笔记:
- 对于是列表中第一个条目的情况
\SubItem
,这需要使用\IgnoreMissingItemError%
(在下面的 MWE 中注释掉)。
警告:
在这个答案对
mdframed
和项目之间的奇怪互动,egreg 提到重新定义
\item
可能很危险,而且会产生不可预测的结果我没有看到这里有任何问题,但我并不是这方面的专家。
代码:
\documentclass[a4paper, 12pt, parskip, headsepline]{scrreprt}
\usepackage{enumitem}
\makeatletter
%% Allow for lists to have no items.
%% https://tex.stackexchange.com/q/86547/4301
\newcommand\IgnoreMissingItemError{\let\@noitemerr\relax}
\makeatother
\newlength\WidthOfBullet
\settowidth\WidthOfBullet{$\bullet$}
%% https://tex.stackexchange.com/a/84235/4301
\newlist{SubItemList}{itemize}{1}
\setlist[SubItemList]{label={},left=-\dimexpr\labelsep+\WidthOfBullet+1.0ex\relax}
\let\OldItem\item
\newcommand{\SubItemStart}[1]{%
\let\item\SubItemEnd
\begin{SubItemList}[resume]%
\OldItem #1%
}
\newcommand{\SubItemEnd}[1]{%
\end{SubItemList}%
\let\item\OldItem
\item #1%
}
\newcommand*{\SubItem}[1]{%
\SubItemStart{#1}%
}%
\begin{document}
This is a normal text that should be left aligned.
\begin{itemize}
%\IgnoreMissingItemError% <--- Need this if want to use \SubItem as first "item"
%\SubItem This is frist text over multiple lines that I want to have aligned
% equally to the to the following list
\item normal list text
\SubItem This is second text over multiple lines that I want to have aligned
equally to the to the following list
\item This is item 1.
\SubItem This is third text over multiple lines that I want to have aligned
equally to the to the following list
\item And this is a second item.
\end{itemize}
\end{document}
答案3
我结合了你们的回答,让它运行得很好。非常感谢!
它使用以下代码:
\documentclass[a4paper, 12pt, parskip]{scrreprt}
\usepackage{changepage}
\usepackage{calc}
\newenvironment{indentitemi}{\begin{adjustwidth}{\labelwidth-\widthof{\labelitemi}}{0pt}}{\end{adjustwidth}}
\begin{document}
This is a normal text that should be left aligned.
\begin{indentitemi}
This is another text over multiple lines that I want to have aligned equally to the bullets of the following list:
\end{indentitemi}
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\end{document}
另外两点说明:
• 如果您正在使用该lmodern
包,则必须将项目符号重新定义为第一级项目标签。因为拉丁现代字体在项目符号左右添加了一些空间。因此缩进仍然看起来很糟糕。
为了消除这种情况,请使用以下修改:
\renewcommand\labelitemi{\(\vcenter{\hbox{\scriptsize\(\bullet\)}}\)}
• 如果您处于类似定理的环境中definition
,例如 ,则 的值\labelwidth
将设置为零,因此不可用。这就是为什么您需要缩进环境的调整版本:
\newenvironment{indentitemi}{\begin{adjustwidth}{\leftmargin-\labelsep-\widthof{\labelitemi}}{0pt}}{\end{adjustwidth}}
答案4
这是一个使用 的解决方案enumitem
。它定义了一个alignedtext
列表环境,其中的项目与环境的项目符号对齐itemize
,但没有任何项目标签。因此,使用alignedtext
列表项目创建的段落只是缩进为itemize
列表项目符号的文本段落。
如果需要的话,可以使用命令调整长度setlist
。
\documentclass[a4paper, 12pt, parskip, headsepline]{scrreprt}
\usepackage{enumitem}
\setlist[itemize]{%
label=\textbullet,
leftmargin=2.5em,
itemindent=0em,
labelindent=1em,
labelwidth=1em,
labelsep=!
}
\newlist{alignedtext}{itemize}{1}
\setlist[alignedtext]{%
label={},
leftmargin=1.5em,
itemindent=0em,
labelindent=0em,
labelwidth=0em,
labelsep=!
}
\begin{document}
This is a normal text that should be left aligned.
\begin{alignedtext}
\item This is another text over multiple lines that I want to have aligned equally to the bullets of the following list:
\end{alignedtext}
\begin{itemize}
\item This is item 1.
\item And this is a second item.
\end{itemize}
\end{document}