5 请问tikz中如何让像平行四边形这样的非规则图形随着里面文字内容的增多而伸缩长度以适应多出来的文字内容?

发布于 2022-10-31 11:28:52

请问tikz中如何让像平行四边形这样的非规则图形随着里面文字内容的增多而伸缩长度以适应多出来的文字内容?如下面这个标题盒子中的平行四边形里面,我想填充内容进去,但是它没法伸缩,导致内容一多就溢出,所以想请问,应该如何让latex计算内容宽度并将宽度值传到要node的非规则图形的长度?

\documentclass[12pt,fontset=ubuntu]{ctexbook}
\usepackage{zhlipsum}
\usepackage{tikz}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shadows,calc,positioning}
\newcommand{\parallelogram}[4][fill,color=teal]{
    \path[#1]
    (#3)--([xshift=#2]#3)--(#4)--([xshift=-#2]#4)--cycle;
}
\newtcolorbox{wwexample}[2][]{%
arc=0mm,
breakable,drop fuzzy shadow=black!20!white,
enhanced,
colback=gray!10,
boxrule=0pt,
top=10mm, 
fontupper=\normalsize,
overlay unbroken = {%
    \node[] at ([xshift=3.2cm,yshift=5pt]frame.north west) {
        \begin{tikzpicture}
        \parallelogram[fill,color=magenta]{4pt}{0,4pt}{1.5pt,0}
        \end{tikzpicture}
    };
    \fill[magenta,drop shadow={opacity=.5, shadow xshift=0.02cm,shadow yshift=-0.02cm}]
    ([xshift=-21pt,yshift=-5pt]frame.north west)--([xshift=-15pt,yshift=-5pt]frame.north west)--([xshift=-21pt,yshift=-1.5cm+25pt]frame.north west)--([xshift=-27pt,yshift=-1.5cm+25pt]frame.north west)--cycle;
    \fill[magenta,drop shadow={opacity=.5, shadow yshift=-0.05cm}]
    (frame.north west) coordinate (ln)--([xshift=3cm]frame.north west) --([xshift=2.5cm,yshift=-1.5cm+20pt]frame.north west) coordinate (rs)--([xshift=2.5cm-3cm,yshift=-1.5cm+20pt]frame.north west)--cycle;
    \node[text=white,font=\bfseries] at ($(ln)!0.5!(rs)$) {Example ~ 1.1.13};
    \fill[white,drop shadow={opacity=.5, shadow xshift=0.05cm,shadow yshift=-0.05cm}]
    ([xshift=3cm]frame.north west) coordinate (lnii)--([xshift=7cm]frame.north west)--([xshift=6.5cm,yshift=-1.5cm+20pt]frame.north west) coordinate (rsii)--([xshift=2.5cm,yshift=-1.5cm+20pt]frame.north west)--cycle;
    \node[text=red,font=\bfseries] at ($(lnii)!0.5!(rsii)$) {#2};
    \fill[magenta,drop shadow={opacity=.5, shadow xshift=0.05cm,shadow yshift=-0.05cm}]
    ([xshift=-5pt,yshift=10pt]frame.north west) coordinate (nw)--([xshift=15pt]nw)--([xshift=-5pt,yshift=-1.5cm]nw)--([xshift=-20pt,yshift=-1.5cm]nw)--cycle;
    \node[] at ([xshift=2.7cm,yshift=-5pt]frame.north west) {
        \begin{tikzpicture}
        \parallelogram[fill,color=white]{4pt}{0,4pt}{1.5pt,0}
        \end{tikzpicture}
    };
    \node[] at ([xshift=6.7cm,yshift=-5pt]frame.north west) {
        \begin{tikzpicture}
        \parallelogram[fill,color=magenta]{4pt}{0,4pt}{1.5pt,0}
        \end{tikzpicture}
    };
}
#1}
\begin{document}
\begin{wwexample}{测试内容}
\zhlipsum[1]
\end{wwexample}
\end{document}

查看更多

关注者
1
被浏览
742
寄存器
寄存器 2022-10-31
这家伙很懒,什么也没写!

建议能整理好MWE来提问,不过给你一个简单的回复,希望能有点用。

\documentclass{ctexart}

\usepackage{tikz}

\usetikzlibrary{shapes.geometric} % 几何形状

% 输入/输出框样式
\tikzset{
  io/.style={draw,
      trapezium,                 % 平行四边形
      trapezium left angle=70,   % 平行四边形左倾角
      trapezium right angle=110, % 平行四边形右倾角
  }
}

\begin{document}
    
  \begin{tikzpicture}
    \node[io] at (0,0) {知的};
    \node[io] at (0,1) {长长的};
    \node[io] at (0,2) {长长长长长长长长知的};        
  \end{tikzpicture}
    
\end{document}

image.png

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览