3

I would be extremely grateful to get some help with this following problem: I would like to have following outcome:

Wished outcome

Where the grey box is all the way out in the margin, but the image and the rest of the text in the document has a specific margin. I would also like to include a listing of text in the colored box.

Closest I can get is this:

\noindent
\fcolorbox{MyGray2}{MyGray2}{\parbox{\paperwidth-3.0\fboxsep-3.0\fboxrule}{\includegraphics[scale=0.1, left=5in]{cvbild.jpg}}{Hejhejhejhejhejhej akj kajhf kjhj hkdjfh skdjfh ksdjfg kdsg }}

However is the margin to the left still white and the text doesn't come even close to where I want it.

Another try was to make a \mybox and change the margins just over the box, but then I get a new page before and after the box.

\newtcolorbox{mybox}{
    arc=0pt,
    boxrule=0pt,
    colback=MyGray2,
   % width=0.2\textwidth,   % this option controls the width of the box
    colupper=black,
    fontupper=\bfseries
}

\begin{document}  
\newgeometry{left=0in,right=0in} % set new margins  
\nopagebreak[4] % doesn't work  
\begin{mybox}  
\includegraphics[scale=.1, left]{cvbild.jpg}{example varfö alajlkejf ksdf }  
\end{mybox}  
\restoregeometry % restore margins
  • 1
    Have a look into the tcolorbox package – MaxNoe Feb 1 '15 at 18:13
  • \paperwidth-3.0\fboxsep-3.0\fboxrule} is wrong as you want 2 not 3 presumably and either it should be \textwidth or you need to use \hspace*{-\@oddsidemargin-1in} so that the box starts flush to the paper edge not flush to the text area. – David Carlisle Feb 1 '15 at 18:42
4

One could use tcolorbox or mdframed, for example, but this can also be done without those powerful packages using some boxes (for example, a \makebox, a \parbox of width equal to \paperwidth, a \colorbox and some minipages for the inner contents); something along these lines:

\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{lipsum}% just to generate filler text

\begin{document}

\lipsum[4]

\par\medskip
\noindent\makebox[\linewidth][c]{%
  \colorbox{gray!30}{%
    \parbox{\paperwidth}{%
      \hspace*{\dimexpr\hoffset+\oddsidemargin+1in\relax}%
      \begin{minipage}{.2\textwidth}
        \includegraphics[width=\linewidth,height=3cm]{example-image-a}
      \end{minipage}%
      \begin{minipage}{.05\textwidth}
        \mbox{}
      \end{minipage}%
      \begin{minipage}{.75\textwidth}
        Some other text\par\bigskip
        \begin{tabular}{@{}ll@{}}
        Email \\
        Phone \\
        Address
        \end{tabular}
      \end{minipage}%
    }%
  }%
}\par\medskip

\lipsum[4]

\end{document}

The result:

enter image description here

  • I found this ansower very useful (for me) – touhami Feb 1 '15 at 20:07
3

My answer uses tcolorbox. A macro \mybox is contructed which takes the picture file name and the text content as parameters. Also, tcolorbox options may be given.

I commented the following source code to help you to adapt the settings for your application:

\documentclass{article}
\usepackage{lipsum}

\usepackage[skins,xparse]{tcolorbox}

\NewTotalTColorBox{\mybox}{ O{} m +m }{%
  enhanced,sidebyside,size=tight,boxrule=0pt,frame hidden,
  lower separated=false,fontlower=\sffamily,
  extrude left by=\dimexpr\hoffset+\oddsidemargin+1in\relax,
  extrude right by=\dimexpr\paperwidth-\textwidth-\hoffset-\oddsidemargin-1in\relax,
  colback=gray!30,%               <-- color
  lefthand width=0.2\textwidth,%  <-- width of picture
  sidebyside gap=1cm,%            <-- distance between picture and text
  before skip=8pt,%               <-- space before
  after skip=8pt,%                <-- space after
  #1
}{\includegraphics[width=\linewidth]{#2}\tcblower #3}


\begin{document}

\lipsum[2]

\mybox{photo.png}
{
  Listet text here\par\bigskip
  \begin{tabular}{@{}ll@{}}
  Email    & a@b.com\\
  Phone    & 555 666\\
  Address  & Green Lane, Hometown
  \end{tabular}
}

\lipsum[3]

% Example: optionally adapt picture width
\mybox[lefthand width=0.3\textwidth]
  {example-image-a.png}
{
  Listet text here\par\bigskip
  \begin{tabular}{@{}ll@{}}
  Email    & a@b.com\\
  Phone    & 555 666\\
  Address  & Green Lane, Hometown
  \end{tabular}
}

\lipsum[4]

\end{document}

The result is:

enter image description here

1

Here I just used a stack.

\documentclass[12pt]{article}
\usepackage[usestackEOL]{stackengine}
\def\stacktype{L}\def\stackalignment{l}
\usepackage{xcolor,graphicx, lipsum}
\begin{document}
\sffamily
\lipsum[1]
\noindent\addstackgap{\stackon[0pt]{%
   \makebox[\textwidth]{\textcolor{blue!10}{\rule{1.01\paperwidth}{6\baselineskip}}}%
}{%
  \includegraphics[width=1.1in,height=6\baselineskip]{example-image-a}%
  \hspace{.5in}%
  \raisebox{.7\baselineskip}{\Longstack{Listed text here\\ \\Email\\Phone\\Address}}%
}}
\noindent Margins here for the rest of the text
\end{document}

enter image description here

0
\documentclass{article}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[remember picture,overlay]
\node[fill=gray!20, right, 
      text height=5\baselineskip, 
      text width=\paperwidth,
      yshift=-2.2in  % top margin++
      ] at (current page.north west) {};
\end{tikzpicture}
\fbox{\includegraphics[height=5\baselineskip]{image}}\hspace*{1cm}
\begin{minipage}[b]{.5\textwidth}\sffamily
list\\[\baselineskip]name\\tel\\email
\end{minipage}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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