首页 > 解决方案 > LaTex 中的警告声明?

问题描述

问题:

我使用下面的代码在我的 LaTex 文档中使用了警告语句,但我需要将警告符号与显示当前和预期的下图中的文本中心对齐。如何?

\newlist{Caution}{enumerate}{1}
\setlist[Caution]{label=\scshape{\color{black}\colorbox{yellow}{{\textbf{{\faWarning} caution}}}},leftmargin=*}

\begin{Caution}
\item {A hazardous situation which, if not avoided, could result in minor or moderate njury.} 
\end{Caution}

在此处输入图像描述

编辑 1:最小可重现示例

\documentclass[11pt,a4paper]{article}
\usepackage[a4paper,bindingoffset=0mm,left=20mm,right=20mm,%
top=30mm,bottom=20mm,footskip=10mm,headsep=10mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{enumitem}
\usepackage{xcolor, fontawesome}
\usepackage{multicol}
\twocolumn
\newlist{Caution}{enumerate}{1}
\setlist[Caution]{label=\scshape{\color{black}\colorbox{yellow}{{\textbf{{\faWarning} caution}}}},leftmargin=*}
\begin{document}
\begin{Caution}
        \item {A hazardous situation which, if not avoided, could result in minor or moderate injury.} 
\end{Caution}
\end{document}

标签: latex

解决方案


您可以使用该命令控制任何框的垂直位置,\raisebox这可用于升高或降低标签。但这对于您的问题不是一个好主意,因为必须降低标签的数量取决于项目文本中的行数。此外,将可选的定位参数传递给标签并不是很容易,而且这种解决方案确实缺乏灵活性,但我将其包含在内是为了比较和完整性。

我用 s 提出了另一种解决方案minipage。将警告标签和文本放在 minipages 中并指定中心 ( [c]) 垂直对齐就足够了。
任何一个部分的宽度都是用calc包计算的,它适应字体大小的修改。有一个可选参数允许控制标签和文本之间的间距。此参数的默认值模仿列表中的间距,但可以根据需要进行调整。

\documentclass[11pt,a4paper]{article}
\usepackage[a4paper,bindingoffset=0mm,left=20mm,right=20mm,%
top=30mm,bottom=20mm,footskip=10mm,headsep=10mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{palatino}
\usepackage{enumitem}
\usepackage{xcolor, fontawesome}
\usepackage{multicol}
\usepackage{calc}
\twocolumn

\newcommand{\cautionmark}{\scshape{\color{black}\colorbox{yellow}{\faWarning caution}}}
\newlist{Caution}{enumerate}{1}
\setlist[Caution]{label=\raisebox{-0.5cm}[0pt][0pt]{\cautionmark},leftmargin=*}

\newcommand{\newcaution}[2][0.7em]{
  \begin{minipage}[c]{\widthof{\cautionmark}}
    \cautionmark
  \end{minipage}%
  \hfill%
  \begin{minipage}[c]{\linewidth-\widthof{\cautionmark}-#1}
    #2
  \end{minipage}
}
\begin{document}

\begin{Caution}
  \item A hazardous situation which, if not avoided, could result in
        minor or moderate injury.
\end{Caution}

\newcaution{A hazardous situation which, if not avoided, could result 
in minor or moderate injury.}

\newcaution[1cm]{A hazardous situation which, if not avoided, could result 
in minor or moderate injury.}
\end{document}

在此处输入图像描述


推荐阅读