tikz 노드는 오른쪽으로 오프셋됩니다.

tikz 노드는 오른쪽으로 오프셋됩니다.

이전에 만든 다이어그램을 tikz노드 및 positioning. 모든 노드를 상대적으로 정의했지만(예: right = of <other node>) 어떤 이유로 노드의 마지막 두 행이 오른쪽으로 오프셋되었습니다. 제 생각에는 상대적으로 잘못된 노드의 위치를 ​​설정한 것 같은데 어떻게 해결될지 모르겠습니다.

다음은 현재 코드 베이스입니다.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[margin=1in]{geometry}

\usetikzlibrary{shapes.geometric, arrows, positioning}
\tikzstyle{red-rounded-rectangle} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, align=center]
\tikzstyle{green-rounded-rectangle} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=green!30, align=center]
\tikzstyle{blue-rounded-rectangle} = [rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=blue!30, align=center]

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=0.5cm]
\node (scotus) [green-rounded-rectangle, text width = 10cm]{
{\Huge \textbf{The Supreme Court}}
};
\node (state) [green-rounded-rectangle, right = of scotus, text width=4cm]{
{\large \textbf{State Supreme Court}}\\
Highest Law of the State
};
\node (12-appeals) [red-rounded-rectangle, below = of scotus,, text width = 4cm]{
{\large \textbf{12 Federal Courts of Appeals}}\\
Hears Appeals from lower courts. Geographically distributed.
};
\node (94-district) [blue-rounded-rectangle, below = of 12-appeals,, text width=4cm]{
{\large \textbf{94 District Courts}}\\
Hears cases and deals verdicts. \textit{Judge Judy} except federal.
};
\node (court-appeals) [red-rounded-rectangle, below = of scotus, right = of 12-appeals,, text width=4cm]{
{\large \textbf{Court of Appeals for the Federal Circuit}}\\
Hears special federal appeals. (e.g. patents)
};
\node (legis-courts) [blue-rounded-rectangle, below= of court-appeals, right = of 94-district, text width = 4cm]{
{\large \textbf{Legislative Courts}}\\
Weaker Courts created by Congress. (E.g. \textit{Court of Military Appeals})
};
\node (state-appeals) [red-rounded-rectangle, below  = of  state, right = of court-appeals, text width = 4cm]{
{\large \textbf{State Court of Appeals}}\\
Hears Appeals from Trials on a Case-By-Case basis.
};
\node (trial-court) [blue-rounded-rectangle, below = of state-appeals, right = of legis-courts, text width=4cm]{
{\large \textbf{Trial Court}}\\
Your typical \textit{Judge Judy} case. Hears either criminal or civil cases, and deals verdicts.
};
\end{tikzpicture}
\end{figure}

\end{document}

다음은 내가 얻는 결과입니다. 여기에 이미지 설명을 입력하세요

아래는 내가 변환하려는 원하는 출력입니다. 여기에 이미지 설명을 입력하세요

참고: 원본 사진의 화살표는 오프셋이 해결된 후 추가할 계획인 기능입니다.

답변1

기본적으로 below'내 앵커를 이 다른 노드의 앵커 north와 정렬'을 의미합니다. south그리고 그게 바로 Ti케이Z는 그렇습니다. 하지만 두 개를 하나 아래에 맞추려고 하기 때문에 노드를 왼쪽으로 이동하려고 합니다. 가장 쉬운 방법은 두 번째 행의 마지막 노드를 이전 두 노드 앞에 놓는 것입니다.

예를 들어,

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows.meta, positioning}
\tikzset{
  red-rounded-rectangle/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30, align=center},
  green-rounded-rectangle/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=green!30, align=center},
  blue-rounded-rectangle/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=blue!30, align=center},
}
\begin{document}
\begin{tikzpicture}[node distance=0.5cm, >/.tip=Latex, thick]
  \node (scotus) [green-rounded-rectangle, text width = 10cm]{
    {\Huge \textbf{The Supreme Court}}
  };
  \node (state) [green-rounded-rectangle, right = of scotus, text width=4cm]{
    {\large \textbf{State Supreme Court}}\\
    Highest Law of the State
  };
  \node (state-appeals) [red-rounded-rectangle, below  = of  state, text width = 4cm]{
    {\large \textbf{State Court of Appeals}}\\
    Hears Appeals from Trials on a Case-By-Case basis.
  };
  \node (12-appeals) [red-rounded-rectangle, left=of state-appeals -| scotus, text width = 4cm] {
    {\large \textbf{12 Federal Courts of Appeals}}\\
    Hears Appeals from lower courts. Geographically distributed.
  };
  \node (94-district) [blue-rounded-rectangle, below = of 12-appeals,, text width=4cm]{
    {\large \textbf{94 District Courts}}\\
    Hears cases and deals verdicts. \textit{Judge Judy} except federal.
  };
  \node (court-appeals) [red-rounded-rectangle, right = of scotus |- state-appeals, text width=4cm]{
    {\large \textbf{Court of Appeals for the Federal Circuit}}\\
    Hears special federal appeals. (e.g. patents)
  };
  \node (legis-courts) [blue-rounded-rectangle, below= of court-appeals, text width = 4cm]{
    {\large \textbf{Legislative Courts}}\\
    Weaker Courts created by Congress. (E.g. \textit{Court of Military Appeals})
  };
  \node (trial-court) [blue-rounded-rectangle, below = of state-appeals,  text width=4cm]{
    {\large \textbf{Trial Court}}\\
    Your typical \textit{Judge Judy} case. Hears either criminal or civil cases, and deals verdicts.
  };
  \draw [->] (trial-court) edge (state-appeals) (state-appeals) edge (state) (state) edge (scotus) (legis-courts) edge (court-appeals) (court-appeals) edge (scotus.south -| court-appeals) (94-district) edge (12-appeals) (12-appeals) -- (12-appeals |- scotus.south) ;
\end{tikzpicture}
\end{document}  

arrows또한 더 이상 사용되지 않는 및 사용을 피하기 위해 코드를 업데이트했습니다 \tikzstyle. 항상 더 크 듯이, text centered가지고 align=center있고 아무것도 하지 않는 경우에는 의미 가 없습니다 .minimum width=3cmtext width

정렬된 법원

답변2

다음은 상자를 더 균일하게 보이도록 더미 노드와 최소 높이를 추가한 약간 다른 답변입니다.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[margin=1in]{geometry}

\usetikzlibrary{shapes.geometric, arrows, positioning}
\tikzset{red-rounded-rectangle/.style={rectangle, rounded corners, minimum
width=3cm, minimum height=2.2cm,text centered, draw=black, fill=red!30,
align=center,text width = 4.5cm},green-rounded-rectangle/.style={rectangle, rounded corners,
minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=green!30,
align=center,minimum height=1.5cm},blue-rounded-rectangle/.style = {rectangle, rounded corners,
minimum width=3cm, minimum height=2cm,text centered, draw=black, fill=blue!30,
align=center,text width = 4.5cm}}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}[node distance=0.5cm,font=\sf]
\node (scotus) [green-rounded-rectangle, text width = 10cm]{
{\Huge \textbf{The Supreme Court}}
};
\node (state) [green-rounded-rectangle, right = of scotus]{
{\large \textbf{State Supreme Court}}\\
Highest Law of the State
};
\node[below =1.5cm of scotus,xshift=0.4cm](dummy){};
\node (12-appeals) [red-rounded-rectangle,left=of dummy]{
{\large \textbf{12 Federal Courts of Appeals}}\\
Hears Appeals from lower courts. Geographically distributed.
};
\node (94-district) [blue-rounded-rectangle, below = of 12-appeals,]{
{\large \textbf{94 District Courts}}\\
Hears cases and deals verdicts. \textit{Judge Judy} except federal.
};
\node (court-appeals) [red-rounded-rectangle, below = of scotus, right = of 12-appeals]{
{\large \textbf{Court of Appeals for the Federal Circuit}}\\
Hears special federal appeals. (e.g. patents)
};
\node (legis-courts) [blue-rounded-rectangle, below= of court-appeals, right = of 94-district]{
{\large \textbf{Legislative Courts}}\\
Weaker Courts created by Congress. (E.g. \textit{Court of Military Appeals})
};
\node (state-appeals) [red-rounded-rectangle, below  = of  state, right = of court-appeals]{
{\large \textbf{State Court of Appeals}}\\
Hears Appeals from Trials on a Case-By-Case basis.
};
\node (trial-court) [blue-rounded-rectangle, below = of state-appeals, right = of legis-courts, text width=4.5cm]{
{\large \textbf{Trial Court}}\\
Your typical \textit{Judge Judy} case. Hears either criminal or civil cases, and deals verdicts.
};
\draw[thick,-latex] (trial-court)--(state-appeals);
\draw[thick,-latex] (legis-courts)--(court-appeals);
\draw[thick,-latex] (94-district)--(12-appeals);
\draw[thick,-latex] (state-appeals)--(state);
\draw[thick,-latex] (court-appeals)--(court-appeals|-scotus.south);
\draw[thick,-latex] (12-appeals)--(12-appeals|-scotus.south);
\draw[thick,-latex] (state)--(scotus);
\end{tikzpicture}
\end{figure}

\end{document}

여기에 이미지 설명을 입력하세요

답변3

일부는 다른 답변과 얼마나 유사하지만 이미지가 아래에서 위로 그려지기 때문에 노드 스타일이 다르게 결정되고 "대법원"의 너비가 계산됩니다. 결과적으로 노드가 잘못 배치되지 않습니다.

%\documentclass{article}
%\usepackage[utf8]{inputenc}
%\usepackage{tikz}
%\usepackage[margin=1in]{geometry}
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning}

\begin{document}
%\begin{figure}[htb]
%\centering
    \begin{tikzpicture}[
node distance = 6mm and 4mm,
   box/.style = {rectangle, rounded corners, thick,
                 draw=#1!70!gray, fill=#1!30,
                 text width=4cm, minimum height=1cm, align=flush center,
                 font=\sffamily\linespread{.8}\selectfont}
                        ]
% first row, on the bottom
\node (94-district)     [box=blue]
   {\textbf{94 District Courts}\\
    \scriptsize
    Hears cases and deals verdicts. \textit{Judge Judy} except federal.};
\node (legis-courts)    [box=blue, right=of 94-district]
   {\textbf{Legislative Courts}\\
    \scriptsize
    Weaker Courts created by Congress. (E.g. \textit{Court of Military Appeals})};
\node (trial-court)     [box=blue, below right=0mm and 4mm of legis-courts.north east]
   {\textbf{Trial Court}\\
    \scriptsize
    Your typical \textit{Judge Judy} case. Hears either criminal or civil cases, and deals verdicts.};
% second row
\node (12-appeals)      [box=red, above=of 94-district]
   {\textbf{12 Federal Courts of Appeals}\\
    \scriptsize
    Hears Appeals from lower courts. Geographically distributed.};
\node (court-appeals)   [box=red, above=of legis-courts]
   {\textbf{Court of Appeals for the Federal Circuit}\\
    \scriptsize
    Hears special federal appeals. (e.g. patents)};
\node (state-appeals)   [box=red, above=of trial-court]
   {\textbf{State Court of\\ Appeals}\\
    \scriptsize
    Hears Appeals from Trials on a Case-By-Case basis.};
% third row
% firs calculate spreme court node width
\path   let \p1 = ($(12-appeals.west)-(court-appeals.east)$),
            \n1 = {veclen(\x1,\y1)} in
        node (scotus)
            [box=green, font=\sffamily\Huge\bfseries,
             text width=\n1-2*\pgfkeysvalueof{/pgf/inner xsep},
             above=of $(12-appeals.north)!0.5!(court-appeals.north)$]
            {The Supreme Court};
\node (state)       [box=green, right = of scotus]
   {\large\textbf{State Supreme Court}\\
    \scriptsize
    Highest Law of the State};
\draw [-Stealth, thick]
    (trial-court)   edge (state-appeals)
    (state-appeals) edge (state)
    (state)         edge (scotus)
    (legis-courts)  edge (court-appeals)
    (court-appeals) edge (scotus.south -| court-appeals)
    (94-district)   edge (12-appeals)
    (12-appeals)     to  (12-appeals |- scotus.south) ;

\end{tikzpicture}
%\end{figure}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보