1

My code is:

\documentclass{article}
\usepackage[table]{xcolor}
\definecolor{background}{rgb}{1,0.62502,0}
\usepackage{wrapfig}
\setlength\intextsep{0pt}
\usepackage{lipsum}

\begin{document}

\lipsum[1] \begin{wrapfigure}{l}{6.5cm} \noindent \fcolorbox{background}{background}{ \begin{minipage}{0.5\textwidth} Some text. \lipsum[4] %\fcolorbox{frame color}{box background color}{text} \end{minipage}} \end{wrapfigure} \lipsum[1]

\end{document}

Which gives:

enter image description here

I'm mostly satisfied with this, but it's clear that the lines of text in the minipage environment (further in the wrapfigure environment) is not clearly horizontally aligned with the surrounding text. Is there a way to horizontally align the lines of text within the wrapfig environment with the surrounding text?

When I removed the internal minipage environment, I think that did get the job done of horizontally aligning the text. However, I would like to keep the minipage environment to keep the background colour of my wrapped text.

arara
  • 776

1 Answers1

3

Use the optional minipage parameter to achieve alignment with the first (top) baseline: \begin{minipage}[t]{0.5\textwidth}

This optional argument position governs how the minipage vertically aligns with the surrounding material.

\fboxsep sets the distance from the frame to the enclosed box. The default is 3pt.

Set it to 0pt with \setlength{\fboxsep}{0pt}.

b

\documentclass{article}
\usepackage[table]{xcolor}
\definecolor{background}{rgb}{1,0.62502,0}
\usepackage{wrapfig}
\setlength\intextsep{0pt}
\usepackage{lipsum}

\begin{document}

\lipsum[1]
\begin{wrapfigure}{l}{6.5cm}
    \noindent
    \setlength{\fboxsep}{0pt}% added <<<<<<<<<<<<<<
    \fcolorbox{background}{background}{%
        \begin{minipage}[t]{0.5\textwidth} % changed <<<<<<<<<<<<
            Some text. \lipsum[4]
            %\fcolorbox{frame color}{box background color}{text}
    \end{minipage}}
\end{wrapfigure}
\lipsum[1]

\end{document}

Simon Dispa
  • 39,141
  • This worked, thanks. Unfortunately my use of the hyperref package still disjoins the alignment to the slightest degree (related: https://tex.stackexchange.com/questions/124986/hyperref-adds-vertical-space-to-listings) but it's not easy to notice and I will try seeing if there's an alternative to hyperref to get around this. – arara Apr 14 '22 at 15:56
  • @arara Why don't you ask another question that shows the problem with the hyperref? – Simon Dispa Apr 14 '22 at 19:57
  • I think it would be considered duplicate (see the question I linked). – arara Apr 16 '22 at 16:01
  • @arara The other question and answer was related with listing. When I add hyperref here I fail to see the loss of alignment you mention. – Simon Dispa Apr 16 '22 at 16:06
  • actually it looks to be the caption package, will post – arara Apr 16 '22 at 16:34