无法在 tikz 图表文本中获取新行

无法在 tikz 图表文本中获取新行

看这个:

\begin{tikzpicture}
    \path (0,1) node[draw,rectangle,rounded corners,fill=green!80]{$P$} (0,-1) node[draw,rectangle,rounded corners,fill=green!80]{$Q$} (2,0) node[draw,rectangle,rounded corners,fill=green!80]{black \\ box};
\end{tikzpicture}

结果如下:
在此处输入图片描述

你知道为什么吗?

以下是完整文件:

% Preview source code

%% LyX 2.3.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[a4paper,english,hebrew]{article}
\usepackage{fontspec}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\parindent}{0bp}
\usepackage[unicode=true,pdfusetitle,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Textclass specific LaTeX commands.
\usepackage{theorem}
\theorembodyfont{\upshape}
\newtheorem{theorem}{\R{משפט}}[section]
\AtBeginDocument{\make@lr\thetheorem}

% The following chunk fixes export with XeTeX.
% It is needed because polyglossia is used by default
% and \make@lr is only defined by babel.
\@ifundefined{make@lr}
{\def\make@lr#1{\begingroup
    \toks@=\expandafter{#1}%
    \edef\x{\endgroup
  \def\noexpand#1{\noexpand\@number{\the\toks@}}}%
  \x}}{\relax}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Yehuda CLM}
\AtBeginDocument{
\renewcommand\footnoterule{%
  \kern -3pt
  \hbox to \textwidth{\hfill\vrule height 0.4pt width .4\textwidth}
  \kern 2.6pt
}}
\usepackage{tikz}

\makeatother

\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\begin{document}
\begin{tikzpicture}
    \path (0,1) node[draw,rectangle,rounded corners,fill=green!80]{$P$} (0,-1) node[draw,rectangle,rounded corners,fill=green!80]{$Q$} (2,0) node[draw,rectangle,rounded corners,fill=green!80]{black \\ box};
\end{tikzpicture}
\end{document}

谢谢你!!

(我计划在完成节点后画线)

答案1

使用align=center、 或其他选项(如left或 )right

在此处输入图片描述

\documentclass[tikz,margin=0.5cm]{standalone}
\begin{document}
\begin{tikzpicture}
    \path (0,1) node[draw,rectangle,rounded corners,fill=green!80]{$P$} (0,-1) node[draw,rectangle,rounded corners,fill=green!80]{$Q$} (2,0) node[draw,rectangle,rounded corners,fill=green!80,align=center]{black \\ box};
\end{tikzpicture}
\end{document}

答案2

大部分内容都离题了(因为你已经得到了解决方案),但是其中一些建议可能对你有用:

  • 你们大部分的序言与你们的问题无关,请下次尝试将其减少到最低限度,即提供最少的工作示例(mwe)
  • 对于相似的节点,定义样式是明智的,例如rbox/.style = {rectangle, draw, rounded corners, fill=#1, align=center},具有用于确定填充颜色的自由参数
  • 您可以定义默认节点颜色
  • 给节点命名(为了简单绘制它们之间的线条)

    \documentclass[a4paper,english,hebrew]{article}
    \usepackage{tikz}
    
    \begin{document}
        \begin{tikzpicture}[
    rbox/.style   = {rectangle, draw, rounded corners, fill=#1, align=center},
    rbox/.default = green!80,
                            ]
    \path   (0, 1) node (p)     [rbox]{$P$}
            (0,-1) node (q)     [rbox]{$Q$}
            (2, 0) node (bb)    [rbox=red!20]{black\\ box};
    \draw[->]   (p) -| (bb);
    \draw[->]   (q) -| (bb);
        \end{tikzpicture}
    \end{document}
    

在此处输入图片描述

相关内容