
我的程式碼是:
\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}
這使:
我對此非常滿意,但很明顯,小型頁面環境中的文字行(進一步在包裝圖環境中)與周圍的文字沒有明顯水平對齊。有沒有辦法將 wrapfig 環境中的文字行與周圍的文字水平對齊?
當我刪除內部小型頁面環境時,我認為這確實完成了水平對齊文字的工作。但是,我想保留小型頁面環境以保留換行文字的背景顏色。
答案1
使用可選的 minipage 參數來實現與第一條(頂部)基線的對齊:\begin{minipage}[t]{0.5\textwidth}
此可選參數位置控制小型頁面如何與周圍材料垂直對齊。
\fboxsep
設定從框架到封閉框的距離。預設值為 3 磅。
使用 將其設為 0pt \setlength{\fboxsep}{0pt}
。
\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}