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.

1 Answer 1

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}
5
  • This worked, thanks. Unfortunately my use of the hyperref package still disjoins the alignment to the slightest degree (related: tex.stackexchange.com/questions/124986/…) but it's not easy to notice and I will try seeing if there's an alternative to hyperref to get around this.
    – arara
    Commented Apr 14, 2022 at 15:56
  • @arara Why don't you ask another question that shows the problem with the hyperref? Commented Apr 14, 2022 at 19:57
  • I think it would be considered duplicate (see the question I linked).
    – arara
    Commented Apr 16, 2022 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. Commented Apr 16, 2022 at 16:06
  • actually it looks to be the caption package, will post
    – arara
    Commented Apr 16, 2022 at 16:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .