3

This question already has an answer here:

I'm trying to create an alert box to show some info, with background color and an icon to the left. With the help of this question I've figured out to come up with this:

\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}

enter image description here

But, as you can see in the picture, when I put the picture and the text inside a colorbox, the content gets aligned to the right.

How can I center the box? Or What is correct way to do this task.

marked as duplicate by Werner, Fran, Guido, jub0bs, Sean Allred Oct 25 '13 at 3:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

Well, you can do for instance the following, which quite generates what you've got:

\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}
  • Great! It works! I'll try too with that question mentioned by @Werner that seems good too. Thanks. – rendon Oct 24 '13 at 19:40
3

@tohecz's answer solves my question but I ended up using this:

\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}

Here is the ouput:

enter image description here

Based on the answer to this other question.

Not the answer you're looking for? Browse other questions tagged or ask your own question.