![微量元素](https://rvso.com/image/348624/%E5%BE%AE%E9%87%8F%E5%85%83%E7%B4%A0.png)
繼續我的上一個問題: 有沒有辦法\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}
如果不是,我可以以某種方式輸出徽標的大小以手動計算確切的比例嗎?我可以用 指定具體高度(以毫米為單位)嗎\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)
。但預設情況下,該節點有一些內部 sep,我們必須將其設為 0: inner sep=0pt
。此外,該節點周圍有一個 width 的底層框\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}