我尝试使用以下代码:
\textbf{Input:}
\begin{itemize}
\item[] Values of \(x\) over a mini-batch: \(\mathcal{B}=\left\{x_{1 \ldots m}\right\}\);
\item[] Parameters to be learned: \(\gamma, \beta\)
\end{itemize}
\textbf{Output:} \(\left\{y_{i}=\mathrm{BN}_{\gamma, \beta}\left(x_{i}\right)\right\}\)
但是,我只能得到如下图所示的输出:
您能否帮助我,如何将项目对齐,使其与“输入:”文本从同一行开始,以便输出与第一幅图像相同?
答案1
您可以将itemize
环境放置在顶部对齐的位置minipage
。我还将使用description
环境来分组和组织“外部”项目(输入、输出)。这样,您就无需进行繁琐的视觉格式化,而是专注于文档的内容。
\documentclass{article} % or some other suitable document class
\usepackage{enumitem}
\begin{document}
\begin{description}
\item[Inputs]
\begin{minipage}[t]{0.8\textwidth}
\begin{itemize}[noitemsep,left=5pt,label=\textendash]
\item Values of \(x\) over a mini-batch: \(\mathcal{B}=\{x_{1},\ldots,x_{m}\}\)
\item Parameters to be learned: \(\gamma\), \(\beta\)
\end{itemize}
\end{minipage}
\item[Output] \(\{y_{i}=\mathrm{BN}_{\gamma, \beta}(x_{i})\}\)
\end{description}
\end{document}
答案2
使用列表来列出外部项目:
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{description}[labelwidth=1.5cm,leftmargin=!]
\item [Input:]
\begin{trivlist}
\item Values of \(x\) over a mini-batch: \(\mathcal{B}=\left\{x_{1
\ldots m}\right\}\);
\item Parameters to be learned: \(\gamma, \beta\)
\end{trivlist}
\item[Output:]\(\left\{y_{i}=\mathrm{BN}_{\gamma,
\beta}\left(x_{i}\right)\right\}\)
\end{description}
\end{document}
答案3
使用 enumitem 包:
请注意,itemize(任何列表)都会添加垂直空间,因此Input:
需要放在项目标签中。
\documentclass{article}
\usepackage{enumitem}
\usepackage{showframe}% alignment tool
\newsavebox{\tempbox}
\begin{document}
\savebox{\tempbox}{\textbf{Input:}}% measure width
\begin{itemize}[leftmargin={\dimexpr \wd\tempbox+\labelsep}]
\item[\usebox\tempbox] Values of \(x\) over a mini-batch: \(\mathcal{B}=\left\{x_{1 \ldots m}\right\}\);
\item[] Parameters to be learned: \(\gamma, \beta\)
\end{itemize}
\noindent\textbf{Output:}\hspace{\labelsep}\(\left\{y_{i}=\mathrm{BN}_{\gamma, \beta}\left(x_{i}\right)\right\}\)
\end{document}