如何使 \parshape 在 tikz 节点内工作?

如何使 \parshape 在 tikz 节点内工作?

预期输出(第二行比第一行缩进多 5mm,第三行及以下行比第二行缩进多 5mm):

\documentclass{article}
\begin{document}
  \setlength{\parindent}{0pt}
  \parshape=3 5mm 40mm 10mm 35mm 15mm 30mm
  This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4. This is sentence 5.
\end{document}

错误输出(tikz):

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \path node[draw,text width=50mm]
      { \setlength{\parindent}{0pt}
        \parshape=3 5mm 40mm 10mm 35mm 15mm 30mm
        This is sentence 1. This is sentence 2. This is sentence 3. This is sentence 4. This is sentence 5.
      };
  \end{tikzpicture}
\end{document}

答案1

只需输入\par命令即可解决问题:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \path node[draw,text width=50mm]
      { \setlength{\parindent}{0pt}
        \parshape=3 5mm 40mm 10mm 35mm 15mm 30mm
        This is sentence 1. This is sentence 2. This is sentence 3.
        This is sentence 4. This is sentence 5.\par
      };
  \end{tikzpicture}
\end{document}

答案2

将文本放入\parbox

在此处输入图片描述

此外,您还可以使用来font=设置\parshape,然后它只是有效(尽管我不确定这是不是一个好主意)。

代码:

\documentclass{article}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \path node[draw,text width=50mm]
          {\parbox{\linewidth}{%
              \setlength{\parindent}{0pt}
                \parshape=3 5mm 40mm 10mm 35mm 15mm 30mm
                This is sentence 1. 
                This is sentence 2. 
                This is sentence 3. 
                This is sentence 4. 
                This is sentence 5.%
          }%
      };
  \end{tikzpicture}
\end{document}

代码:

\begin{document}
  \begin{tikzpicture}
    \path node[draw,text width=50mm, font={\parshape=3 5mm 40mm 10mm 35mm 15mm 30mm}]
       {%
            This is sentence 1. 
            This is sentence 2. 
            This is sentence 3. 
            This is sentence 4. 
            This is sentence 5.%
      };
  \end{tikzpicture}
\end{document}

相关内容