Vertical align (top) graphic and top of text-line
Vertical align (top) graphic and top of text-line
I want to align the top of an image, and the top of a line of text. Below is a MWE with the current setup (using a placeholder "graphic" but the effect seems the same) and the desired behavior.
documentclassarticle
usepackagegraphicx
begindocument
beginminipage[t]0.5textwidth
%includegraphics[height=0.4in]theimage.png
rule0.95textwidth0.5in
endminipage%
beginminipage[t]0.5textwidth
sometext to fill the line
endminipage
enddocument
MWE behavior:
Desired behavior:
Isn't this what you want? tex.stackexchange.com/questions/29143/…
– Oleg Lobachev
Aug 22 at 12:45
thanks to both of you, I was having trouble locating these resources by searches. Should have searched harder I guess.
– amoodie
Aug 22 at 13:56
3 Answers
3
A simple way to fix your problem is by adding vspace0pt
as soon as a minipage is created:
vspace0pt
documentclassarticle
usepackagegraphicx
begindocument
beginminipage[t]0.5textwidth
vspace0pt
%includegraphics[height=0.4in]theimage.png
rule0.95textwidth0.5in
endminipage%
beginminipage[t]0.5textwidth
vspace0pt
sometext to fill the line
endminipage
enddocument
This also feels a little hacky (similar to my answer below) but it works. Can you explain why adding the zero-height vspace works in this case?
– amoodie
Aug 22 at 13:57
You could use adjustbox
, as marmot suggested in his comment.
adjustbox
Moreover, instead of using minipage
s, you could use a tabularx
.
minipage
tabularx
documentclassarticle
usepackagetabularx
usepackagegraphicx
usepackage[export]adjustbox
begindocument
noindentbegintabularxlinewidth@X@hspace2ptX@
includegraphics[height=0.4in, width=0.475textwidth,valign=t]example-image
&
sometext to fill the line \
endtabularx
enddocument
A potential workaround I found is that if I know the height of the image, I can add a negative vspace. This seems kind of hacky though and I'm wondering if there is a cleaner solution
documentclassarticle
usepackagegraphicx
begindocument
beginminipage[t]0.5textwidth
% includegraphics[height=0.4in]theimage.png%
rule0.95textwidth4baselineskip
endminipage%
beginminipage[t]0.5textwidth
vspace*-4baselineskip
sometext to fill the line
endminipage
enddocument
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Welcome to TeX.SE! Please have a look at this post.
– marmot
Aug 22 at 4:00