考虑以下代码:
\documentclass{book}
\hoffset 10pt \voffset -55pt
\oddsidemargin 17pt \evensidemargin 18pt \topmargin 35pt
\headheight 25pt \textheight 8.25in \textwidth 5.75in
\headsep 40pt \marginparwidth 35pt
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\thispagestyle{empty}
{\par \centering
\begin{minipage}{0.89\textwidth}
\begin{bclogo}[
couleur=red!15, % background color
marge=10, % margin in pt
epBord=2.5, % border width
arrondi=0, % corner radius
ombre=true, % shadow
blur, % blur
couleurBord=red!15, % border color
logo=, % no built-in logo
barre=none, %snake, % border style
tailleOndu=1.5 % border amplitude (zigzag)
]
{\fontsize{15}{19}\selectfont \textbf{This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence}}
\end{bclogo}
\end{minipage}
\par}
\begin{center}
\begin{tikzpicture}[pencildraw/.style={ %
decorate,
decoration={random steps,segment length=2pt,amplitude=1pt}
} %
]
\node[
preaction={fill=black,opacity=.5,transform canvas={xshift=1mm,yshift=-1mm}},
pencildraw,draw,fill=black!30,text width=0.89\textwidth,inner sep=5mm,align=justify]
{\fontsize{15}{19}\selectfont \textbf{This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.}};
\end{tikzpicture}
\end{center}
\end{document}
产生
在这种特殊情况下,tikzpicture
文本宽度 = 0.89\textwidth
,textwidth
在序言中指定为 5.75 英寸。
我正在将嵌入到环境bclogo
中minipage
。但是,当我指定\begin{minipage}{0.89\textwidth}
--- 时,我得到了您在图片中看到的内容。
我希望 的bclogo
长度与 下面的 相同tikzpicture
;并且,我希望 将bclogo
直接放置在 上方。但是,当我将tikzpicture
的宽度增加到更大的值以接近 的宽度时,相对而言, 似乎位于 的左侧略微偏左的位置。minipage
0.89\textwidth
tikzpicture
bclogo
tikzpicture
问题:我怎样才能取textwidth
的指定值tikzpicture
(在本例中0.89\textwidth
为 ,但一般为其他值)并bclogo
以所述方式创建 ,使其长度等于 的长度tikzpicture
;并将 置于bclogo
的正上方tikzpicture
?我正在使用 进行编译pdflatex
。
谢谢。
答案1
更新
使用同一节点上的两个节点,tikzpicture
可以很容易地将一个节点放在另一个节点之上。上面的节点(名为bclogo
)logo
和下面的节点使用below = of logo
。
您可以设置下部节点文本宽度(\setlength{\tikztextwidth}{<lenght>}
)及其内部分隔(\setlength{\tikzmargin}{<lenght>}
)。元素的总宽度将是\tikztextwidth+ 2\tikzmargin
为了匹配宽度,我minipage
在顶部节点使用了相同宽度。
在您的代码中,内容的长文本bclogo
位于标题字段中。现在它位于环境的主体中。
% !TeX TS-program = pdflatex
\documentclass{book}
\hoffset 10pt \voffset -55pt
\oddsidemargin 17pt \evensidemargin 18pt \topmargin 35pt
\headheight 25pt \textheight 8.25in \textwidth 5.75in
\headsep 40pt \marginparwidth 35pt
\usepackage{xcolor}
\usepackage[tikz]{bclogo}
\usepackage{tikz}
\usetikzlibrary{positioning}% added <<<<<<<<<<<<<<
\usetikzlibrary{decorations.pathmorphing}
%****************************************** added <<<<<<<<<<<<
\newlength{\tikztextwidth}
\newlength{\tikzmargin}
\newlength{\bcepborder}
\setlength{\tikztextwidth}{0.89\textwidth}% set the text width of both elements <<<<<<<<<<<<<<
\setlength{\tikzmargin}{20pt} % set the interior margin in both elements <<<<<<<<<<<<<<<<<<<<<
\setlength{\bcepborder}{3pt} % set bclogo border width (no decimals) <<<<<<<<<<<<<
\makeatletter
\newcounter{bcmarge}
\newcounter{epborder}
\setcounter{bcmarge}{\strip@pt\tikzmargin}
\setcounter{epborder}{\strip@pt\bcepborder}
\makeatother
%******************************************
\begin{document}
\thispagestyle{empty}
\begin{center}
\begin{tikzpicture}[pencildraw/.style={ %
decorate,
decoration={random steps,segment length=2pt,amplitude=1pt}
} %
]
\node(logo) {
\begin{minipage}{\dimexpr \tikztextwidth+ 2\tikzmargin+2\bcepborder}%<<<<<<<<<<<<<<<<<<<<<<<
\begin{bclogo}[
epBord=\theepborder, % border width
couleurBord=red!15, % border color
couleur=red!15, % background color
marge=\thebcmarge, % margin in pt %<<<<<<<<<<<<<<<<<<<<<<<
ombre=true, % shadow
blur, % blur
logo=, % no built-in logo
barre=none, %snake, % border style
]
{} \fontsize{15}{19}\selectfont \bfseries This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.
\end{bclogo}
\end{minipage}};
\node[
preaction={fill=black, opacity=.5, transform canvas={xshift=1mm,yshift=-1mm}
},
pencildraw,
draw,
fill=black!30,
text width=\tikztextwidth,%<<<<<<<<<<<<<<<<<<<<<<<
inner sep=\tikzmargin+\bcepborder,%<<<<<<<<<<<<<<<<<<<<<<<
font=\fontsize{15}{19}\selectfont \bfseries,
align=justify,
below = of logo]
{This is a sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence. This is another sentence.};
\end{tikzpicture}
\end{center}
\end{document}