我在 TikZ 手册第 1022 页中发现,线条有 3 个部分,颜色和宽度各不相同:一个内部线宽和两个外部线。
但这有一个pgfpicture
-code...
我问自己:我怎样才能在形状中使用它?
我想要一个内线(粉色,5mm)和上下两条外线(黑色,非常细)。 那可能吗?
暗示:我不想画三个独立的形状(强力解决方案很清楚)。
\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
TikZ-Manual, p. 1122:
\begin{pgfpicture}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{1cm}{1cm}}
\pgfpathlineto{\pgfpoint{1cm}{0cm}}
\pgfsetlinewidth{2pt}
\pgfsetinnerlinewidth{1pt}
\pgfsetinnerstrokecolor{red!50}
\pgfusepath{stroke}
\end{pgfpicture}
How to use here?
\begin{tikzpicture}[]
\node[rounded rectangle, draw, pink,
minimum width=50mm, minimum height=20mm, line width=5mm,
](s){*};
\end{tikzpicture}
\end{document}
答案1
您可以应用preaction
较粗的线条或postaction
较细的线条:
\documentclass[margin=5mm, varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[]
\node[rounded rectangle, draw=pink, line width=5mm,
minimum width=50mm, minimum height=20mm, preaction={draw=red, line width=6mm},
](s){*};
\end{tikzpicture}
\end{document}
答案2
如果您对内线和外线具有相同的样式感到满意,则可以使用以下线条double
:
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\node[
rounded rectangle,
minimum width=50mm,
minimum height=20mm,
draw=black,
line width=0.5mm,
double=pink,
double distance=5mm
] (s) {*};
\end{tikzpicture}
\end{document}
答案3
前三个示例(手册中的示例之后)展示了如何使用 TikZ 执行与 PGFpicture 完全相同的操作。TikZ 不提供直接接口,\pgfsetinnerlinewidth
但也会调整外(见下文)使用double distance
或之一时的线宽。不过,我添加了一个直接界面,需要用户自行调整。double distance between line centers
\pgfsetinnerlinewidth
line width
当你使用double
(或\pgfsetinnerlinewidth
)PGF/TikZ 绘制两次路径时,首先使用“外”线宽/颜色,然后使用内线宽/颜色。
这意味着内线宽需要小于外线宽以double
产生视觉效果(除非不透明度发挥作用)。
这可能也是 TikZ 确保 PGF 线宽(成为外线宽)进行调整,以便double distance
将double distance between line centers
线宽(由用户指定)添加到内行宽
- 在“两侧”内线宽与
double distance
和 - 这样它就覆盖了给定的宽度
double distance between line centers
(我希望我最后的 TikZpicture 比我的文字更清晰)。
因为你想要
[…] 有一个内线(粉色,5mm)和上下两条外线(黑色,非常细)。
你需要
double distance = 5mm
和
line width = <very thin>
并且 PGF/TikZ 将用 绘制黑线,line width = 5mm + 2 × <very thin>
但随后直接覆盖一条带子,5mm
留下黑色条纹<very thin>
。
我使用了ultra thin
(0.1pt),但你当然可以调整它。
代码
\documentclass[margin=5mm, tikz]{standalone}
\usetikzlibrary{shapes.misc}
\makeatletter
\tikzset{inner line width/.code=%
\tikzset{double}\pgfmathsetlength\pgf@x{#1}%
\edef\tikz@double@setup{\noexpand\pgfsetinnerlinewidth{\the\pgf@x}}}
\makeatother
\begin{document}
\begin{tikzpicture}
\pgfpathmoveto{\pgfpointorigin}
\pgfpathlineto{\pgfpoint{1cm}{1cm}}
\pgfpathlineto{\pgfpoint{1cm}{0cm}}
\pgfsetlinewidth{2pt}
\pgfsetinnerlinewidth{1pt}
\pgfsetinnerstrokecolor{red!50}
\pgfusepath{stroke}
\end{tikzpicture}
\tikz
\draw[
line width = .5pt, % \pgfsetlinewidth{.5pt}
double distance = 1pt, % \pgfsetinnerlinewidth{1pt}
% and \pgfsetlinewidth {1pt + 2 * \pgflinewidth}
double=red!50 % \pgfsetinnerstrokecolor{red!50}
] (0pt, 0pt) % \pgfpathmoveto{\pgfpointorigin}
-- (1cm, 1cm) % \pgfpathlineto{\pgfpoint{1cm}{1cm}}
-- (1cm, 0cm) % \pgfpathlineto{\pgfpoint{1cm}{0cm}}
; % \pgfusepath{stroke}
\tikz
\draw[
line width = .5pt, % \pgfsetlinewidth{.5pt}
double distance between line centers = 1.5pt,
% \pgfsetinnerlinewidth{\pgflinewidth - 1.5pt}
% and \pgfsetlinewidth {\pgflinewidth + 1.5pt}
double = red!50 % \pgfsetinnerstrokecolor{red!50}
] (0pt, 0pt) -- (1cm, 1cm) -- (1cm, 0cm);
\tikz
\draw[line width=2pt, inner line width=1pt, double=red!50]
(0pt, 0pt) -- (1cm, 1cm) -- (1cm, 0cm);
\tikz
\node[rounded rectangle, draw, double=pink, double distance=5mm, ultra thin,
minimum width=50mm, minimum height=20mm](s){*};
\begin{tikzpicture}
\draw[step=5mm] (-.25,-.25) grid (3.25,2.8);
\tikzset{double=red, nodes={white, align=center, scale=.4}}\ttfamily
\draw[double distance=5mm, line width=2mm] (0,0.25) -- node{dd = 5mm, lw = 2mm\\→ ilw = 5mm, olw = 5 + 2×2mm} + (right:3);
\draw[double distance between line centers=5mm, line width=2mm] (0,1.25) -- node{ddblc = 5mm, lw = 2mm\\→ ilw = 5mm - 2mm, olw = 5mm + 2mm} + (right:3);
\draw[inner line width=5mm, line width=10mm] (0,2.25) -- node{ilw = 5mm, lw = 10mm\\→ ilw = 5mm, olw = 10mm} + (right:3);
\end{tikzpicture}
\end{document}