我正在尝试创建一个警告框来显示一些信息,带有背景颜色和左侧的图标。借助此问题我想出了这个:
\documentclass[letterpaper,12pt,twoside]{report}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{warningbackground}{RGB}{252,226,158}
\usepackage{floatflt}
\newcommand{\alertwarningbox}[1]{
\centering
\colorbox{warningbackground}{\parbox{400pt} {
\vskip 10pt
\begin{floatingfigure}[l]{50pt}
\includegraphics[scale=1.0]{AlertWarning.pdf}
\end{floatingfigure}
#1
\vskip 10pt
}
}
}
\newcommand{\alertwarning}[1]{
\vskip 10pt
\begin{floatingfigure}[l]{50pt}
\includegraphics[scale=1.0]{AlertWarning.pdf}
\end{floatingfigure}
#1
\vskip 10pt
}
\begin{document}
Text...
\alertwarning{
Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message .
}
Text...
\alertwarningbox{
Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message .
}
\end{document}
但是,正如您在图片中看到的,当我将图片和文本放在里面时colorbox
,内容会向右对齐。
我怎样才能将盒子置于中央?或者什么是完成这项任务的正确方法。
答案1
好吧,您可以执行以下操作,这将产生您所得到的结果:
\documentclass[letterpaper,12pt,twoside]{report}
\usepackage{graphicx}
\usepackage{colortbl,array}
\usepackage{tabularx}
\definecolor{warningbackground}{RGB}{252,226,158}
\newcommand{\alertwarningbox}[1]{
\centering
\begin{tabularx}{\linewidth}{
>{\columncolor{warningbackground}}c
>{\columncolor{warningbackground}}X}
\raisebox{\dimexpr2\baselineskip-\height}
{\includegraphics[scale=1.0]{AlertWarning.pdf}}&
\raisebox{\tabcolsep}{\strut}#1\raisebox{-\tabcolsep}{\strut}
\end{tabularx}
}
\begin{document}
Text...
Text...
\alertwarningbox{
Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message.
Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message Warning message.
}
\end{document}
答案2
@tohecz 的回答解决了我的问题,但我最终使用了这个:
\documentclass{book}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{infobackground}{RGB}{217,237,247}
\definecolor{infoforeground}{RGB}{58,135,173}
\definecolor{infoborder}{RGB}{188,232,241}
\usepackage{environ}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds,calc}
\NewEnviron{alertinfo}[1]
{
\begin{tikzpicture}
\node[inner sep=0pt,
draw=infoborder,
line width=1.2pt,
fill=infobackground] (box) {\parbox[t]{.95\textwidth}
{%
\begin{minipage}{.15\textwidth}
\centering\tikz[scale=3]
\node[scale=1]
{
\includegraphics[scale=0.8]{AlertInfo.pdf}
};
\end{minipage}%
\begin{minipage}{.75\textwidth}
\vskip 10pt
\textbf{\textcolor{infoforeground}{#1}}\par\smallskip
\textcolor{infoforeground}{\BODY}
\par\smallskip
\end{minipage}\hfill
}%
};
\end{tikzpicture}
}
\begin{document}
\begin{alertinfo}{Info title}
The info message goes here.
\end{alertinfo}
\end{document}
输出如下:
根据另一个答案问题。