TikZ:菱形中的对角文字

TikZ:菱形中的对角文字

我需要制作一个带有水平文本的菱形,或者相应地在正方形中制作一个对角线文本,就像所示的两幅图像一样。

使用 TikZ 可以简单地实现这一点吗?

菱形中的对角文字 菱形中的分项文本

编辑:似乎第二个带有 itemize 的图无法使用 shapeparnode 完成,而第一个图的最佳方法是 shapeparnode。对于第二个图,我最终使用了节点内的 minipage。

如果有人有办法很好地列出文本的各个部分并使其居中,我仍然会非常感兴趣!

第二幅图的代码:

\documentclass[11pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{rotating}

\begin{document}

\begin{tikzpicture}
    \draw (0,0) rectangle (7.778174593,7.778174593)
        node[rotate=45,pos=.5, text width=7cm] {
            \begin{minipage}{\linewidth}
            \begin{center}
            Praktisk information:
            \end{center}
            \\
            \begin{itemize}
                \item Husk kød til fredag aften
                \item Husk sengelinned, dyne og pude eller sovepose
                \item Mountainbikecampens adresse er Slettestrandvej 26, 9690 Fjerritslev
                \item Ønskeseddel kan findes på ???
            \end{itemize}
            \end{minipage}
    };
\end{tikzpicture}

\end{document}

答案1

根据 Bobyandbob 的要求,我在下面发布了我的解决方案。如上面的评论所述,它基于这个答案,但解决方案仍然需要对空格进行一些手动调整。

\documentclass[12pt]{standalone}

\usepackage{shapepar}
\usepackage{tikz}
\usetikzlibrary{calc,fit,intersections}
\usepackage{rotating}
\usepackage[cmintegrals,cmbraces]{newtxmath}
\usepackage{ebgaramond-maths}


\def\shapeparnodeaccuracy{2}
\newcommand\shapeparnode[6][]{
  % 6 parameters:
  % style for node (default:empty),
  % h margin, v margin, left path, right path, text (just one paragraph!)

  % name left and right paths and compute there bounding boxes
  \begin{scope}[local bounding box=leftbb]
    \path[name path global=left,xshift=#2] #4;
  \end{scope}
  \node[inner ysep=-#3,inner xsep=0pt,fit=(leftbb)](leftbb){};
  \begin{scope}[local bounding box=rightbb]
    \path[name path global=right,xshift=-#2] #5;
  \end{scope}
  \node[inner ysep=-#3,inner xsep=0pt,fit=(rightbb)](rightbb){};

  % global bounding box
  \path let
  \p1=(leftbb.north west), \p2=(leftbb.south west),
  \p3=(rightbb.north east), \p4=(rightbb.south east)
  in
  \pgfextra{
    \pgfmathsetmacro{\ymin}{(\y1 < \y3) ? \y1 : \y3}
    \pgfmathsetmacro{\ymax}{(\y2 > \y4) ? \y2 : \y4}
    \typeout{ymin \ymin}
    \typeout{ymax \ymax}
  } node[inner sep=0,fit={(\x1,\ymin pt)(\x3,\ymax pt)}](mybb){};

  % compute nb steps
  \path let \p1=(mybb.north), \p2=(mybb.south) in
  \pgfextra{
    \pgfmathsetmacro{\fnthght}{1em/\shapeparnodeaccuracy}
    \pgfmathtruncatemacro{\nbsteps}{(\y1-\y2)/\fnthght}
    \xdef\nbsteps{\nbsteps}
    \typeout{nb steps \nbsteps}
  };

  % horizontal references
  \path (mybb.north) -- (mybb.south)
  \foreach \cnt in {0,1,...,\nbsteps}{
    \pgfextra{\pgfmathsetmacro{\pos}{\cnt/\nbsteps}}
    coordinate[pos=\pos] (ref \cnt)
  };

  % left and right boundaries coordinates
  \foreach \cnt in {0,1,...,\nbsteps}{
    % an horizontal line from left to right
    \path[name path=ltor]
    (mybb.west |- ref \cnt) --  (mybb.east |- ref \cnt);
    % same line from right to left
    \path[name path=rtol]
    (mybb.east |- ref \cnt) -- (mybb.west |- ref \cnt);
    % left boundary
    \path[name intersections={of=rtol and left,by={l \cnt},sort by=rtol}];
    % right boundary
    \path[name intersections={of=ltor and right,by={r \cnt},sort by=ltor}];
  }
  % start point (and initial value of boundshape)
  \path let \p1=(l 0) in 
  \pgfextra{
    \pgfmathsetmacro{\xstart}{\x1}
    \xdef\boundshape{{0}{0}b{\xstart}}
    \xdef\xmin{\xstart}
    \xdef\xmax{\xstart}
  };

  % top and bottom
  \path let \p1=(l 0), \p2=(l \nbsteps) in
  \pgfextra{
    \pgfmathsetmacro{\ystart}{\y1}\xdef\ystart{\ystart}
    \pgfmathsetmacro{\yending}{\y2}\xdef\yending{\yending}
  };
  % incremental definition of boundshape
  \foreach \cnt in {0,1,...,\nbsteps}{
    \path let \p1=(l \cnt), \p2=(r \cnt) in
    \pgfextra{
      \pgfmathsetmacro{\start}{\x1}
      \pgfmathsetmacro{\len}{\x2-\x1}
      \pgfmathsetmacro{\ypos}{\cnt/\nbsteps*(\ystart - \yending)}
      {\let\\=\relax \xdef\boundshape{\boundshape\\{\ypos}t{\start}{\len}}}
      \pgfmathsetmacro{\xmin}{(\xmin < \start) ? \xmin : \start}
      \xdef\xmin{\xmin}
      \pgfmathsetmacro{\xmax}{(\xmax > \start + \len) ? \xmax : \start + \len}
      \xdef\xmax{\xmax}
    };
  }
  % draw the node with text in a shapepar
  \pgfmathsetmacro{\ymax}{\ystart - \yending}
  {\let\\=\relax \xdef\boundshape{\boundshape\\{\ymax}e{0}}}
  \node[#1,text width=\xmax pt - \xmin pt,align=flush left,
  anchor=north west,inner sep=0]
  at (mybb.north west -| \xmin pt,0)
  {\Shapepar[1pt]{\boundshape}#6\par};
}


\begin{document}

\begin{turn}{45}
\begin{tikzpicture}
  \def\pathone{(5.5,0) to (0,-5.5) to (5.5,-11)}
  \def\pathtwo{(5.5,-11) to (11,-5.5) to (5.5,0)}
  \shapeparnode{2.2em}{3.6em}{\pathone}{\pathtwo}{
    Dear Frej
    \\ \textcolor{white}{white space} \\
    Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee
    \\ \textcolor{white}{white space} \\
    \hspace*{2cm} d. ??.-??. april 1001.
    \\ \textcolor{white}{white space} \\
    Wokedee wokedee Wokedee wokedee Wokedee wokedee Wokedee wokedee.
  }
  \draw \pathone -- \pathtwo -- cycle;
\end{tikzpicture}
\end{turn}

\end{document}

相关内容