我正在尝试在我的文档中列出一些项目,以便我可以为项目中的单词添加粗体选项,如下所示:
- 源码包含活动以及 Java 代码。
- 根包含活动以及 Java 代码。
- 资产包含活动以及 Java 代码。
- 垃圾桶包含活动以及 Java 代码。
但是使用此代码创建的项目没有粗体字体选项。如何在itemize
其他环境中实现这一点?
\begin{itemize}
\item src contains the activities as well as the java code.
\item gen
\item assets
\item bin
\end{itemize}
答案1
\textbf
使论点变得大胆。另一种选择是环境description
:
\documentclass{article}
\begin{document}
\begin{itemize}
\item \textbf{src} contains the activities as well as the Java code.
\item \textbf{gen}
\item \textbf{assets}
\item \textbf{bin}
\end{itemize}
\hrule
\begin{description}
\item[src] contains the activities as well as the Java code.
\item[gen]
\item[assets]
\item[bin]
\end{description}
\end{document}
答案2
我建议定义一个新的环境,这样您只需修改相关定义就可以改变它的实现;enumitem
在处理列表时这非常方便。
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum} % for mock text
\newenvironment{descitemize} % a mixture of description and itemize
{\begin{description}[leftmargin=*,before=\let\makelabel\descitemlabel]}
{\end{description}}
\newcommand{\descitemlabel}[1]{%
\textbullet\ \textbf{#1}%
}
\begin{document}
\lipsum*[2]
\begin{descitemize}
\item[src] contains the activities as well as the Java code.
\item[gen]
\item[assets]
\item[bin]
\end{descitemize}
\lipsum*[3]
\begin{description}
\item[src] contains the activities as well as the Java code.
\item[gen]
\item[assets]
\item[bin]
\end{description}
\end{document}
环境description
只是为了比较。
如果希望标记itemize
在嵌套descitemize
环境时与通用标记一致,还需要做更多的工作。
\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum} % for mock text
\newenvironment{descitemize} % a mixture of description and itemize
{\begin{description}[leftmargin=*,before=\let\makelabel\descitemlabel\advanceitemdepth]}
{\end{description}}
\makeatletter
\newcommand{\advanceitemdepth}{%
\ifnum\@itemdepth >\thr@@
\@toodeep
\else
\advance\@itemdepth\@ne
\edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
\fi
}
\newcommand{\descitemlabel}[1]{%
\csname\@itemitem\endcsname\ \textbf{#1}%
}
\makeatother
\begin{document}
\lipsum*[2]
\begin{descitemize}
\item[src] contains the activities as well as the Java code.
\item[gen]
\item[assets]
\item[bin] is divided into two
\begin{descitemize}
\item[zero] for $0$
\item[one] for $1$
\end{descitemize}
\end{descitemize}
\lipsum*[3]
\end{document}
答案3
一个选项是手动将您想要的文本变为粗体。
\begin{itemize}
\item \textbf{src} contains the activities as well as the java code.
\item \textbf{gen}
\item \textbf{assets}
\item \textbf{bin}
\end{itemize}
此外,还有另一种选项,它为您提供了一个用于粗体前缀( )的新环境bolditemize
,同时保留项目符号列表。从视觉上看,它看起来与上面的方法完全相同。
\newenvironment{bolditemize}{\begin{itemize} }{\end{itemize}}
\expandafter\def\expandafter\bolditemize\expandafter{%
\bolditemize \let\olditem\item
\def\item[##1]{\olditem \textbf{##1}}}
\begin{document}
\begin{bolditemize}
\item[src] contains the activities as well as the java code.
\item[gen]
\item[assests]
\item[bin]
\end{bolditemize}
\end{document}