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:



MWE behavior



Desired behavior:



enter image description here





Welcome to TeX.SE! Please have a look at this post.
– marmot
Aug 22 at 4:00





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



Output


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 minipages, 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



enter image description here



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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế