我有一个页面,顶部有一个阴影框。如何让阴影框与页面框架的顶部对齐?有点间隙。我的代码:
\documentclass[10pt]{book}
\usepackage[showframe]{geometry}
\usepackage[x11names]{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{LavenderBlush2}
\usepackage{lipsum}
\begin{document}
\setlength{\OuterFrameSep}{0pt}
\begin{shaded*}
\lipsum[1]
\end{shaded*}
\vfill
\begin{shaded*}
\lipsum[1]
\end{shaded*}
\end{document}
在另一个问题中(将阴影框与页面底部对齐),建议将其设置OuterFrameSep
为 0,以便删除框架环境前后的垂直空间。这似乎对框架环境之后有效,但对之前无效。
答案1
尝试以下方法,它也许对你有用:
\documentclass[10pt]{book}
\usepackage{geometry}
\usepackage[x11names]{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{LavenderBlush2}
\setlength{\OuterFrameSep}{0pt}
\usepackage{etoolbox} % <---
\BeforeBeginEnvironment{shaded*}{\topskip=0pt} % <---
\AfterEndEnvironment{shaded*}{\topskip=10pt} % <---
\usepackage{lipsum}
\usepackage{graphicx}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{shaded*}
\lipsum[1]
\end{shaded*}
\vfill
\begin{shaded*}
\lipsum[1]
\end{shaded*}
\clearpage
\begin{figure}[ht]
\includegraphics[width=\linewidth]{example-image-duck}
\end{figure}
\section{title}\lipsum
\end{document}
答案2
另一种方法是使用软件包tcolorbox
。以下版本可让您对几乎所有内容进行大量控制:
\documentclass[10pt]{book}
\usepackage[showframe]{geometry}
\usepackage[x11names]{xcolor}
\colorlet{shadecolor}{LavenderBlush2}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\begin{document}
\begin{tcolorbox}[boxrule=0mm, boxsep=0mm, sharp corners, colback=shadecolor]
\lipsum[1]
\end{tcolorbox}
\vfill
\begin{tcolorbox}[boxrule=0mm, boxsep=0mm,
after skip=0pt, % this removes some extra space at the bottom
bottom=2ex, top=2ex, right=2ex, left=2ex, % 'padding' between text and border
sharp corners, colback=shadecolor]
\lipsum[1]
\end{tcolorbox}
\end{document}