![tikz 形状带圆角的“胶带”](https://linux22.com/image/349923/tikz%20%E5%BD%A2%E7%8A%B6%E5%B8%A6%E5%9C%86%E8%A7%92%E7%9A%84%E2%80%9C%E8%83%B6%E5%B8%A6%E2%80%9D.png)
我正在尝试使用以下代码来使用带有圆角的形状“胶带”:
\documentclass[12pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{%
shapes,
shadows,
}
\tikzset{
document/.style={
shape=tape,
double copy shadow={shadow xshift=1ex, shadow yshift=-0.8ex},
rounded corners=5pt,
minimum width=5cm,
inner ysep=15pt,
draw,
align=center,
fill=white,
font=\fontsize{20}{20}\sffamily\bfseries,
tape bend top=none,
},
}
\begin{document}
\begin{tikzpicture}
\node[document] (node1) {files};
\end{tikzpicture}
\end{document}
这给了我这个:
关于如何修复右下角的线条有什么建议吗?
答案1
我们可以在 中找到此形状的定义pgflibraryshapes.symbols.code.tex
。我们需要研究的是背景部分:
\backgroundpath{% \tapedimensions% % \pgf@xc\halfwidth% \pgf@yc\halfheight% % \pgf@xc\bendxradius% \pgf@yc\bendyradius% {% \pgftransformshift{\centerpoint}% \pgfpathmoveto{\pgfqpoint{-\halfwidth}{0pt}}% \pgfpathlineto{\pgfqpoint{-\halfwidth}{\halfheight}}% \ifx\topbendstyle\pgf@lib@sh@inandouttext% \pgfpathlineto{\pgf@x-\halfwidth\pgf@y\halfheight\advance\pgf@y\halfbendheight}% \pgfpatharc{225}{315}{\bendxradius and \bendyradius}% \pgfpatharc{135}{45}{\bendxradius and \bendyradius}% \else% \ifx\topbendstyle\pgf@lib@sh@outandintext% \pgfpathlineto{\pgf@x-\halfwidth\pgf@y\halfheight\advance\pgf@y\halfbendheight}% \pgfpatharc{135}{45}{\bendxradius and \bendyradius}% \pgfpatharc{225}{315}{\bendxradius and \bendyradius}% \else% \pgfpathlineto{\pgfqpoint{\halfwidth}{\halfheight}}% \fi% \fi% % ⬇️⬇️⬇️ NOTICE THIS LINE ⬇️⬇️⬇️ (a) \pgfpathlineto{\pgfqpoint{\halfwidth}{-\halfheight}}% \ifx\bottombendstyle\pgf@lib@sh@inandouttext% % ⬇️⬇️⬇️ NOTICE THIS LINE ⬇️⬇️⬇️ (b) \pgfpathlineto{\pgf@x\halfwidth\pgf@y-\halfheight\advance\pgf@y-\halfbendheight}% \pgfpatharc{45}{135}{\bendxradius and \bendyradius}% \pgfpatharc{315}{225}{\bendxradius and \bendyradius}% \else% \ifx\bottombendstyle\pgf@lib@sh@outandintext% \pgfpathlineto{\pgf@x\halfwidth\pgf@y-\halfheight\advance\pgf@y-\halfbendheight}% \pgfpatharc{315}{225}{\bendxradius and \bendyradius}% \pgfpatharc{45}{135}{\bendxradius and \bendyradius}% \else% % ⬇️⬇️⬇️ NOTICE THIS LINE ⬇️⬇️⬇️ (c) \pgfpathlineto{\pgfqpoint{-\halfwidth}{-\halfheight}}% \fi% \fi% \pgfpathclose% }% }
大致来说,绘图如下
- 从西边开始
- 画直线到西北角
- 画直线到东北角
- 画直线到东南角
- 用户想要弧形底部!!
- 向南画一条短直线(仍然在东南角)
- 向西南角画曲线
- 向西画直线,关闭路径
按照前列腺素的低级命令,有两个连续的\pgfpathlineto
命令并且第二行很短。
这会混淆rounded corners
机制,因为前列腺素无法判断你是在向上还是向下。
如果你能用\pgfpathlineto
一个替换这两个,那就没有问题了。例如,你可以将行 (a) 移到 (c),这样无论如何都只有一行。
西北角有一个完全相同的错误。为了证明我的观点,将行 (d) 移至行 (e) 并编译以下 MWE
\documentclass[tikz,border=30]{standalone}
\usetikzlibrary{%
shapes,
shadows,
}
\makeatletter
\def\pgf@sh@bg@tape{
\tapedimensions%
%
\pgf@xc\halfwidth%
\pgf@yc\halfheight%
%
\pgf@xc\bendxradius%
\pgf@yc\bendyradius%
{%
\pgftransformshift{\centerpoint}%
\pgfpathmoveto{\pgfqpoint{-\halfwidth}{0pt}}%
% ⬇️⬇️⬇️ NOTICE THIS LINE ⬇️⬇️⬇️ (d)
\pgfpathlineto{\pgfqpoint{-\halfwidth}{\halfheight}}%
\ifx\topbendstyle\pgf@lib@sh@inandouttext%
\pgfpathlineto{\pgf@x-\halfwidth\pgf@y\halfheight\advance\pgf@y\halfbendheight}%
\pgfpatharc{225}{315}{\bendxradius and \bendyradius}%
\pgfpatharc{135}{45}{\bendxradius and \bendyradius}%
\else%
\ifx\topbendstyle\pgf@lib@sh@outandintext%
\pgfpathlineto{\pgf@x-\halfwidth\pgf@y\halfheight\advance\pgf@y\halfbendheight}%
\pgfpatharc{135}{45}{\bendxradius and \bendyradius}%
\pgfpatharc{225}{315}{\bendxradius and \bendyradius}%
\else%
% ⬇️⬇️⬇️ NOTICE THIS LINE ⬇️⬇️⬇️ (e)
\pgfpathlineto{\pgfqpoint{\halfwidth}{\halfheight}}%
\fi%
\fi%
\ifx\bottombendstyle\pgf@lib@sh@inandouttext%
\pgfpathlineto{\pgf@x\halfwidth\pgf@y-\halfheight\advance\pgf@y-\halfbendheight}%
\pgfpatharc{45}{135}{\bendxradius and \bendyradius}%
\pgfpatharc{315}{225}{\bendxradius and \bendyradius}%
\else%
\ifx\bottombendstyle\pgf@lib@sh@outandintext%
\pgfpathlineto{\pgf@x\halfwidth\pgf@y-\halfheight\advance\pgf@y-\halfbendheight}%
\pgfpatharc{315}{225}{\bendxradius and \bendyradius}%
\pgfpatharc{45}{135}{\bendxradius and \bendyradius}%
\else%
\pgfpathlineto{\pgfqpoint{\halfwidth}{-\halfheight}}%
\pgfpathlineto{\pgfqpoint{-\halfwidth}{-\halfheight}}%
\fi%
\fi%
\pgfpathclose%
}%
}
\tikzset{
document/.style={
shape=tape,
rounded corners=5pt,
minimum width=5cm,
inner ysep=15pt,
draw,
align=center,
fill=white,
font=\fontsize{20}{20}\sffamily\bfseries,
tape bend top=none,
}
}
\begin{document}
\begin{tikzpicture}
\node[document] (node1) {files};
\end{tikzpicture}
\begin{tikzpicture}
\node[document,tape bend top=in and out] (node1) {files};
\end{tikzpicture}
\end{document}