latex - 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}
解决方案
您可以使用该命令控制任何框的垂直位置,\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}
推荐阅读
- python-3.x - 数据增强 CIFAR-10 降低了 CNN 模型的准确性
- sql - 仅选择一组特定的字符 (PostgreSQL)
- flutter - 颤振:使用 open_file 下载并打开文件
- typescript - Firebase 功能:通过 FCM 发送的推送通知的客户端网络套接字断开错误
- python - 如何阻止 Python Rocket 出现在 Python 3.8 中?
- azure - 使用访问密钥对 Azure 存储帐户进行 REST 请求会导致 HTTP 403 Forbidden
- spring-boot - 空对象的返回类型应该是什么?
- node.js - Mongoose 预保存绑定/此关键字不起作用
- notifications - Azure DevOps Server 2019.1 出现“WorkItem 用户交付”作业挂起的问题
- javascript - 用给定的数组创建一个引导 4 卡的循环?