问题:
\setlist
我已成功使用with将定义框垂直居中对齐enumerate
。我希望进行更改,以便每个框的顶部与每个定义的顶部对齐。
最小工作示例(MWE):
\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{lipsum}
% ----------------------------------------------------------------------
% Material Colors
% ----------------------------------------------------------------------
\definecolor{MaterialsCoral}{cmyk}{0, 0.75, 0.5, 0}
\definecolor{MaterialsSky}{cmyk}{0.6, 0, 0, 0}
\definecolor{MaterialsSun}{cmyk}{0, 0.2, 0.6, 0.05}
\definecolor{MaterialsGrass}{cmyk}{0.65, 0, 0.3, 0}
\begin{document}
\newcommand{\specialitem}[3][white]{%
\item[%
\colorbox{#2}{\textcolor{#1}{\makebox[2em]{\strut #3}}}%
]
}
\setlist[enumerate,1]{leftmargin=12mm}
\begin{enumerate}[itemsep=6pt]
\specialitem{MaterialsCoral}{\textbf{H}} \textcolor{MaterialsCoral}{\textbf{Hyper}} \lipsum[2]
\specialitem{MaterialsSky}{\textbf{T}} \textcolor{MaterialsSky}{\textbf{Text}} \lipsum[2]
\specialitem{MaterialsGrass}{\textbf{M}} \textcolor{MaterialsGrass}{\textbf{Markup}} \lipsum[2]
\specialitem{MaterialsSun}{\textbf{L}} \textcolor{MaterialsSun}{\textbf{Language}} \lipsum[2]
\end{enumerate}
\end{document}
期望的结果:
每个框的顶部应向下移动以与每个定义对齐。
答案1
这是对与 配合使用的代码的一个小修改\raisebox
。当然,负提升的值可能需要根据其他字体进行调整。
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{enumitem}
\usepackage{lipsum}
% ----------------------------------------------------------------------
% Material Colors
% ----------------------------------------------------------------------
\definecolor{MaterialsCoral}{cmyk}{0, 0.75, 0.5, 0}
\definecolor{MaterialsSky}{cmyk}{0.6, 0, 0, 0}
\definecolor{MaterialsSun}{cmyk}{0, 0.2, 0.6, 0.05}
\definecolor{MaterialsGrass}{cmyk}{0.65, 0, 0.3, 0}
\begin{document}
\newcommand{\specialitem}[3][white]{%
\item[%
\smash{\raisebox{-1.06ex}{\colorbox{#2}{\textcolor{#1}{\makebox[2em]{\strut #3}}}}}%
]
}
\setlist[enumerate,1]{leftmargin=12mm}
\begin{enumerate}[itemsep=6pt]
\specialitem{MaterialsCoral}{\textbf{H}} \textcolor{MaterialsCoral}{\textbf{Hyper}} \lipsum[2]
\specialitem{MaterialsSky}{\textbf{T}} \textcolor{MaterialsSky}{\textbf{Text}} \lipsum[2]
\specialitem{MaterialsGrass}{\textbf{M}} \textcolor{MaterialsGrass}{\textbf{Markup}} \lipsum[2]
\specialitem{MaterialsSun}{\textbf{L}} \textcolor{MaterialsSun}{\textbf{Language}} \lipsum[2]
\end{enumerate}
\end{document}