8

Look at this:

\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}

This is the result:
enter image description here

Do you have any idea why?

Here is the full file:

% 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}

Thank you!!

(I planed to draw the line after I'll finish the nodes)

2 Answers 2

11

Use align=center, or another option such as left or right.

enter image description here

\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}
5

mostly off-topic (since you already got a solution), however some of suggestions can be useful to you:

  • most of you preamble is not related to your problem, please nesxt time try to reduce it to minimum, i.e. provide minimal working example (mwe)
  • for similar nodes is sensible to define style, for example rbox/.style = {rectangle, draw, rounded corners, fill=#1, align=center}, which has free parameter for determining fill color
  • you can define default nodes color
  • give name to nodes (for simple drawings the lines between them)

    \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}
    

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .