1

The adjustbox package provides a way to vertically align image and a paragraph of text within the tabular environment; I have included an example which shows this:

mwea.tex

\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage[demo]{graphicx}
\usepackage[active,tightpage]{preview}
\usepackage[export]{adjustbox}
\PreviewEnvironment{tabular}
\setlength\PreviewBorder{5pt}
\newlength{\parboxwidth}
\setlength{\parboxwidth}{8.0cm}
\begin{document}
\begin{tabular}[t]{rl}
\midrule
    \adjustbox{valign=t}{\includegraphics[height=2.0cm, keepaspectratio=true]    {image.png}} & %
    \adjustbox{valign=t}{%
    \parbox[t]{\parboxwidth}{%
    \lipsum[1]}
} \\
\midrule
\end{tabular}
\end{document}

Which gives the following output:

ouput from mwe a

Ultimately, I'd like to place a feature very similar to the above as a header using the fancyhdr package. I have included my attempt at this below, however, as the output will attest, I cannot seem to align both the image and the text such that their tops meet the top of the header area. They are aligned to the same vertical position, however, this position is not at the top of the header.

mweab.tex

\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\usepackage{fancyhdr}
\usepackage[showframe,textwidth=245.0pt,%
top=2in,
headheight=1.0in,
headsep=0.20in]{geometry}
\newlength{\parboxwidth}
\setlength{\parboxwidth}{8.0cm}
\begin{document}
\fancypagestyle{plain}{%
\fancyhead[R]{%
    \begin{tabular}{rl}
    \adjustbox{valign=t}{\includegraphics[height=1.0cm, keepaspectratio=true]    {image.png}} & %
    \adjustbox{valign=t}{%
    \parbox[t]{\parboxwidth}{%
    content content content content content content content content content content     content content content content content content content content content content content     content content content content content content content}
}
\end{tabular}
}%
\renewcommand{\headrule}{}%
}%
\makeatletter
\let\ps@firstpage\ps@plain%
\makeatother
\thispagestyle{plain}
\section*{Body}
\lipsum[1]
\end{document}

This gives the ouput:

output from mwe b

Any comments or suggestions are most appreciated.

Supplementary material:

supplementary material

second attempt supplementary material

3
  • Your MWE returns this output for me. As such, it's perfectly fine in terms of the vertical alignment.
    – Werner
    Apr 15, 2014 at 19:01
  • Please see revision. Apr 15, 2014 at 19:11
  • @StevenB.Segletes, Thanks for the revision, I have attached my output; I'm still seeing a gap between the top of the header area and the top of the image and text. I also note that changing the value associated with the textwidth option of the geometry package call on my system is not showing any thinning or broadening of the text. I don't understand why there is no effect.
    – John Chris
    Apr 15, 2014 at 19:24

1 Answer 1

1

You don't need the tabular. One problem was that your figure width plus parbox width plus any left-gap and inter-gap have to add up to \textwidth, so I defined it that way, using \theleftgap, \themidgap and \figurewidth as settable dimensions. Instead of adjustbox, I used \belowbaseline[-\ht\strutbox]{...} to vertically adjust the figure to match a [t] parbox. To get the whole kit and caboodle top aligned, I set a \rule of negative height equal to \headheight.

I commented out the string textwidth=245.0pt, which was causing my MWE to produce very narrow output.

\documentclass{article}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage[demo]{graphicx}
\usepackage{fancyhdr}
\usepackage[showframe,%textwidth=245.0pt,%
top=2in,
headheight=1.0in,
headsep=0.20in]{geometry}
\newlength{\parboxwidth}
\def\figurewidth{3cm}
\def\themidgap{1em}
\def\theleftgap{.5\textwidth}
\setlength{\parboxwidth}{\dimexpr\textwidth-\theleftgap-\figurewidth-\themidgap\relax}
\usepackage{stackengine}
\begin{document}
\fancypagestyle{plain}{%
\fancyhead[c]{\rule[-\headheight]{0pt}{1pt}%
    \hspace{\theleftgap}%
    \belowbaseline[-\ht\strutbox]{\includegraphics[width=\figurewidth, height=1cm]{image.png}}%
    \hspace{\themidgap}\parbox[t]{\parboxwidth}{%
    content content content content content content content content content content     
    content}
}%
\renewcommand{\headrule}{}%
}%
\makeatletter
\let\ps@firstpage\ps@plain%
\makeatother
\thispagestyle{plain}
\section*{Body}
\lipsum[1]
\end{document}

enter image description here

3
  • Thank you very much for the suggestions. I have edited the initial question, adding a supplementary figure, which is what I get when I compile the code suggested above. I'm not sure why there is a discrepancy between your output and mine. Could my system be getting default geometry settings from some configuration file? Also, my motivation in using \fancyhead[R] is to place the image and text in the rightmost third of the header. The supplementary output shows the image and text occupying the entire header.
    – John Chris
    Apr 15, 2014 at 19:01
  • @JohnChris Please see revision. I used a \rule to top align the content. Apr 15, 2014 at 19:32
  • Thank you very much; I see no issue with the compiled result.
    – John Chris
    Apr 15, 2014 at 19:41

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.