私の前の質問: ロゴを特定の高さに拡大縮小する方法はありますか\scalebox
? Tikz で作成したロゴを、同じく Tikz で作成した長方形に配置します。どちらも章のヘッダーとして使用します。\savebox
事前に コマンドを使用してロゴを保存しました。ただし、ロゴの高さを長方形と同じにし、両方の原点を同じにする必要があります。 のような式をheight of the rectangle / \ht\logo
何らかの方法でスケーリング係数として使用することは可能ですか? これは、ロゴが変更された場合に役立ちます。これがコードです。変更する必要があると思われる行がマークされています。
\documentclass[a4paper,11pt,fleqn]{book}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mydarkgray}{RGB}{0,100,100}
\newcommand{\mytemplatecolor}{mydarkgray}
\usepackage{tikz}
\newsavebox{\logo}
\savebox{\logo}{%
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\path[draw=black,fill=black,line join=miter,line cap=round,miter
limit=4.00,nonzero rule,dash phase=3.000pt,line width=0.000pt]
(178.4915,651.0411) .. controls (178.0358,651.0411) and (177.5801,651.0411)..
(177.1244,651.0411) .. controls (177.1244,652.6787) and (177.1244,654.3163) ..
(177.1244,655.9539) .. controls (177.5801,655.9539) and (178.0358,655.9539) ..
(178.4915,655.9539) .. controls (178.4915,654.3163) and (178.4915,652.6787) ..
(178.4915,651.0411) -- cycle;
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-182.0794,658.5070) rectangle
(-177.1244,660.6401);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-280.8165,679.2454) rectangle (-193.6939,684.6964);
\path[xscale=-1.000,yscale=1.000,fill=black,nonzero rule,rounded
corners=0.0000cm] (-280.8165,694.2955) rectangle (-177.1245,696.3244);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-280.8165,716.4833) rectangle
(-177.1245,721.9073);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-185.6345,669.1724) rectangle (-177.1244,673.9126);
\end{tikzpicture}}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}[display]
{\Huge\bfseries\sffamily\color{\mytemplatecolor}}
{\gdef\chapterlabel{\thechapter\ }}
{0pt} % separation between label and chapter-title
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-8cm,xshift=0cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[name path=mainbox,fill=\mytemplatecolor,\mytemplatecolor] (0,0) rectangle(35.5mm,15mm);% mainbox
\path (0,0) ++(0.379\wd\logo,+0.3755\ht\logo) node {\scalebox{0.76} {\usebox{\logo}}};% this works if i would finetune the settings. But i want the Logo to always appear with the exakt height of the mainbox and flush with the page boarder. No tiny overlap anywere as this looks bad when zooming inside the PDF
\node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
{\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};
\node[anchor=north west,yshift=-7.2cm,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
{\parbox[top][30mm][t]{\textwidth}{\color{\mytemplatecolor}#1}};
\end{tikzpicture}
};
\gdef\chapterlabel{} % code before the title body
\end{tikzpicture}
}
\titlespacing*{\chapter}{-98pt}{38pt}{30pt} % [A]
\begin{document}
\chapter{A Chapter}
\end{document}
そうでない場合、ロゴのサイズを出力して、正確な比率を手動で計算することはできますか? で特定の高さを mm 単位で指定できますか\scalebox
?
答え1
egreg が示唆しているように、 を使用できます。\resizebox
これは と同様に機能しますが\scalebox
、スケール係数の代わりにスケール次元を使用します。
\resizebox{<width dim>}{<height dim>}{contents to be scaled}
アスペクト比を維持しながら特定の幅/高さに拡大縮小したい場合、!
従属ディメンションを指定します。たとえば、次のようになります。
\resizebox{!}{<rectangle height>}{\usebox{\logo}}
したがって、\scalebox
部品を交換するだけ\resizebox{!}{15mm}{\usebox{\logo}}
でスケーリングの問題は解消されます。
さて、配置に関する問題と描画自体に関する問題がいくつかあります。まず背景の四角形は、\draw
塗りつぶしオプションで使用されるため、ロゴを配置するときに を処理する必要があります\pgflinewidth
が、線と塗りつぶしは同じ色であるため、 は必要ありません。代わりに\draw
を使用する\path
と、線は描画されなくなります。
次に、ロゴを含むノードに移ります。これは中心で配置されているため、ロゴのサイズが変わるたびに、それに応じて再配置する必要があります。anchor=south west
(オプション と同等above right
) を使用してノードを配置すると、at (0,0)
ノードの「原点」は になります(0,0)
。ただし、ノードには、デフォルトでは内部間隔があるため、0: に設定する必要がありますinner sep=0pt
。さらに、ノードの周囲には幅 の基になるボックスがあり\pgflinewidth
、ロゴと背景ボックスの間に隙間ができます。 またはshift={(45:-\pgflinewidth)}
を設定してline width=0pt
(こちらの方がスマートです)、この小さなスペースを削除できます。そのため、これらすべてを行うと、描画は問題なく表示されるはずです。
ムウェ
\documentclass[a4paper,11pt,fleqn]{book}
\usepackage{xcolor}
\usepackage{color}
\definecolor{mydarkgray}{RGB}{0,100,100}
\newcommand{\mytemplatecolor}{mydarkgray}
\usepackage{tikz}
\usetikzlibrary{intersections}
\newsavebox{\logo}
\savebox{\logo}{%
\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\path[draw=black,fill=black,line join=miter,line cap=round,miter
limit=4.00,nonzero rule,dash phase=3.000pt,line width=0.000pt]
(178.4915,651.0411) .. controls (178.0358,651.0411) and (177.5801,651.0411)..
(177.1244,651.0411) .. controls (177.1244,652.6787) and (177.1244,654.3163) ..
(177.1244,655.9539) .. controls (177.5801,655.9539) and (178.0358,655.9539) ..
(178.4915,655.9539) .. controls (178.4915,654.3163) and (178.4915,652.6787) ..
(178.4915,651.0411) -- cycle;
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-182.0794,658.5070) rectangle
(-177.1244,660.6401);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-280.8165,679.2454) rectangle (-193.6939,684.6964);
\path[xscale=-1.000,yscale=1.000,fill=black,nonzero rule,rounded
corners=0.0000cm] (-280.8165,694.2955) rectangle (-177.1245,696.3244);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,miter limit=4.00,nonzero rule,dash phase=3.000pt,line
width=0.000pt,rounded corners=0.0000cm] (-280.8165,716.4833) rectangle
(-177.1245,721.9073);
\path[xscale=-1.000,yscale=1.000,draw=black,fill=black,line join=miter,line
cap=round,nonzero rule,dash phase=3.000pt,line width=0.000pt,rounded
corners=0.0000cm] (-185.6345,669.1724) rectangle (-177.1244,673.9126);
\end{tikzpicture}}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}[display]
{\Huge\bfseries\sffamily\color{\mytemplatecolor}}
{\gdef\chapterlabel{\thechapter\ }}
{0pt} % separation between label and chapter-title
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-8cm,xshift=0cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\path[name path=mainbox,fill=\mytemplatecolor,\mytemplatecolor] (0,0) rectangle (35.5mm,15mm);% mainbox
\node[line width=0pt, above right=0mm, draw=none, inner sep=0pt] at (0,0) {\resizebox{!}{15mm}{\usebox{\logo}}};
\node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
{\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};
\node[anchor=north west,yshift=-7.2cm,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
{\parbox[top][30mm][t]{\textwidth}{\color{\mytemplatecolor}#1}};
\end{tikzpicture}
};
\gdef\chapterlabel{} % code before the title body
\end{tikzpicture}
}
\titlespacing*{\chapter}{-98pt}{38pt}{30pt} % [A]
\begin{document}
\chapter{A Chapter}
\end{document}