考虑一下代码
\documentclass{book}
\usepackage{type1cm,lettrine}
\usepackage{xcolor}
%\usepackage{lipsum}
\usepackage[tracking=true]{microtype}
\begin{document}
\thispagestyle{empty}
\large
\lettrine[lines=3,loversize=.4,lraise=.15,nindent=.80em,findent=.20em]{\fboxsep10pt\fboxrule15pt\fcolorbox{red}{yellow!75!brown}{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
\end{document}
产生
问题:我怎样才能水平(和垂直)移动fcolorbox
外部红框内的字母?
编辑:不重新定义 fcolorbox 可以做到这一点吗?
我使用 编译了代码pdflatex
。
谢谢。
答案1
\fcolorbox
将绘制一个在所有方向上具有相同内部填充和边框宽度的框。
允许longbox
您分别设置填充和边框的顶部、底部和左侧的宽度。然后可以通过操纵这些参数将内部黄色框移动到外部红色框内。
使用外部红色框的左下角作为原点来定义两个长度\xshift
和。\yshift
原图的\fcolorbox
边框为 15pt,内边距为 10pt。图中显示其longbox
忠实再现了原图。
显然,在这个例子中,偏移的最大值为 25pt,以将黄色框保持在红色框内。
第二张图显示了三个例子。depth=1
添加了第四行。
\documentclass[12pt,a4paper]{article}
\usepackage{longfbox}% added <<<<<<<<<<<<
\newlength{\yshift}
\newlength{\xshift}
\usepackage{type1cm,lettrine}
\usepackage{xcolor}
\usepackage[tracking=true]{microtype}
\begin{document}
\thispagestyle{empty}
\large
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1 ]{\fboxsep10pt\fboxrule15pt\fcolorbox{red}{yellow!75!brown}{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. \emph{With a text more the three lines lraise must be changed or depth added.}
\bigskip
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
\lfbox[border-top-width=15pt,
border-bottom-width=15pt,
border-left-width=15pt,
border-right-width=15pt,
padding-right=10pt,
padding-left=10pt,
padding-top=10pt,
padding-bottom=10pt,
border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. (done with \textbf{longfbox})
\newpage
\setlength{\yshift}{0pt} % bottom left corner
\setlength{\xshift}{0pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
\lfbox[border-top-width=\dimexpr 25pt- \yshift,
border-bottom-width=\yshift,
border-left-width=\xshift,
border-right-width=\dimexpr 25pt- \xshift,
padding-right=10pt,
padding-left=10pt,
padding-top=10pt,
padding-bottom=10pt,
border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. (done with \textbf{longfbox} X = 0pt, Y = 0pt))
\vspace{25pt}
\setlength{\yshift}{4pt}
\setlength{\xshift}{10pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
\lfbox[border-top-width=\dimexpr 25pt- \yshift,
border-bottom-width=\yshift,
border-left-width=\xshift,
border-right-width=\dimexpr 25pt- \xshift,
padding-right=10pt,
padding-left=10pt,
padding-top=10pt,
padding-bottom=10pt,
border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
(done with \textbf{longfbox}; X = 10pt, Y = 4pt)
\vspace{15pt}
\setlength{\yshift}{25pt} % top right corner
\setlength{\xshift}{25pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
\lfbox[border-top-width=\dimexpr 25pt- \yshift,
border-bottom-width=\yshift,
border-left-width=\xshift,
border-right-width=\dimexpr 25pt- \xshift,
padding-right=10pt,
padding-left=10pt,
padding-top=10pt,
padding-bottom=10pt,
border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
(done with \textbf{longfbox}; X = 25pt, Y = 25pt)
\end{document}