Latex colored box across margin and text

415 views Asked by At

In latex, I am trying to make a new command called \bluebar that takes in 4 parameters and creates a colored box that spans the left margin and the textwidth, as shown in the image. The tree image should overhang the box going into the right margin slightly. Margins are both 2cm. I have tried using \colorbox, but I can't seem to get the alignment right. I am not opposed to doing this a completely different way though. Thanks!

enter image description here

Code I have tried (note I define the colors p.blue, p.yellow, and p.white in code not provided):

\newcommand{\bluebar}[4]{%
 \par\medskip
\noindent\makebox[\linewidth][c]{%
  \colorbox{p.blue}{%
    \parbox{\paperwidth}{%
      \hspace*{\dimexpr\hoffset+\oddsidemargin+1cm\relax}%
      
      \begin{minipage}{.05\textwidth}
        \mbox{}
      \end{minipage}%

      \begin{minipage}{.75\textwidth}
        \justifying
          \textbf{\large\textcolor{p.white}{#1}}\\
          \small\textcolor{p.yellow}{#2}\\
          \vspace{5pt} % Top margin
          \small\textcolor{p.white}{#3}
          \vspace{15pt} % Bottom margin
      \end{minipage}%

     \begin{minipage}{.2\textwidth}
        \includegraphics[width=4cm]{#4}
      \end{minipage}%
    }%
  }%
 }
}
1

There are 1 answers

0
Rachel On

I have answered my own question...

\newcommand{\bluebar}[4]{%
  \par\medskip
  \noindent
  \makebox[\linewidth][r]{%
    \colorbox{p.blue}{%
      \parbox{\dimexpr\paperwidth-2cm\relax}{%
        \begin{minipage}{.2\textwidth}
          \mbox{}
        \end{minipage}% 
        \begin{minipage}{.75\textwidth}
          \justifying
          \vspace{15pt} 
      \noindent\textbf{\large\textcolor{p.white}{#1}}\\
          \small\textcolor{p.yellow}{#2}\\
          \newline
          \small\textcolor{p.white}{#3}
          \vspace{15pt} % Bottom margin
        \end{minipage}%
        \begin{minipage}{.05\textwidth}
          \mbox{}
        \end{minipage}%
      \begin{minipage}{.2\textwidth}
          \includegraphics[width=5cm]{#4}
        \end{minipage}%
    }%
    }%
  }%
}