旧答案

旧答案

当我在 TikZ 中写很多东西时,文字会从页面上消失。我想修复这个问题。

在此处输入图片描述

这是我的代码:

\documentclass[12pt,a4paper]{article}
\usepackage[left=3cm,right=3cm,top=1cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}

\node[anchor=west] (c1) {\textbf{one}};
\node [below right = of  c1.south west] (c11) {If  c=1  $\rightarrow$ hello hello hello hello hello hello hello hello hello hello hello hello hello hello     hello hello hello hello hello hello hello};
\node [below=of c11.west,anchor=west] (c12) {If c=0  $\rightarrow$ Aun no han pasado 10 segundos};

\foreach \value in {1,2}
\draw[->] (c1.south west) |- (c1\value.west);

\end{tikzpicture}

\end{document}

如果可能的话,我希望得到以下结果以及其他修改:

在此处输入图片描述

谢谢!!

答案1

默认情况下,节点中不会自动换行,要实现此功能,您需要在节点选项中添加text width。但是,这对于相对于箭头的对齐效果不太好。一种不错的方法是使用\matrix

\documentclass[12pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,matrix}

\begin{document}
\begin{tikzpicture}

\matrix (m) [
   matrix of nodes,
   column 2/.style={text width=8cm}, % width of second column, activates automatic lie breaking
   nodes={anchor=base} 
   ]
 {
  If $c=1 \rightarrow$ & hello hello hello hello hello hello hello hello hello hello
                  hello hello hello hello hello hello hello hello hello hello hello \\
 If $c=0 \rightarrow$ & Aun no han pasado 10 segundos \\
};

\node (one) [
   above left=1cm and 0.3cm of m, % position relative to the matrix
   font=\bfseries, % bold font
   outer ysep=5pt % lines drawn to the node will stop at this distance from the noce
]  {one};

\draw [<-] (m-2-1) -| (one);
\draw [<-] (m-1-1) -- (m-1-1 -| one);

\end{tikzpicture}
\end{document}

在此处输入图片描述

旧答案

一种解决方法是将长文本放在第二个节点中,参见下面的第二个示例。可能有更优雅的方法来实现这一点,但这是我首先想到的。

\documentclass[12pt,a4paper]{article}
\usepackage[left=3cm,right=3cm,top=1cm,bottom=2cm]{geometry}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}

\node[anchor=west] (c1) {\textbf{one}};
\node [below right = of  c1.south west,text width=8cm] (c11) {If  $c=1  \rightarrow$ hello hello hello hello hello hello hello hello hello hello hello hello hello hello     hello hello hello hello hello hello hello};
\node [below=of c11.west,anchor=west] (c12) {If $c=0  \rightarrow$ Aun no han pasado 10 segundos};

\foreach \value in {1,2}
\draw[->] (c1.south) |- (c1\value.west);

\end{tikzpicture}


\begin{tikzpicture}

\node[anchor=west] (c1) {\textbf{one}};
\node [below right=of  c1.south west] (c11) {If  $c=1  \rightarrow$};
\node [right=0pt    of c11.base east,anchor=base west,text width=8cm,outer sep=0pt,inner sep=0pt] {hello hello hello hello hello hello hello hello hello hello
                  hello hello hello hello hello hello hello hello hello hello hello};
\node [below=2cm of c11.west,anchor=west] (c12) {If $c=0  \rightarrow$ Aun no han pasado 10 segundos};

\foreach \value in {1,2}
\draw[->] (c1.south) |- (c1\value.west);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容