写真の配置

写真の配置

2 枚の絵を描きたいのですが、2 枚目の絵は 1 枚目の絵の下に置きます。現在持っているのは次の絵です。

出力

2 番目の画像に最初の画像と同じ x 座標を設定するにはどうすればよいでしょうか?

コード:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}

\tikzset{
    pics/vhsplit/.style n args = {3}{
        code = {
        \node (A) at (0,0) {#1};
        \node[anchor=south west] (B) at (A.east) {#2};
        \node[anchor=north west] (C) at (A.east) {#3};
        \node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {}; 
        \draw (B.north west) -- (C.south west)
              (B.south west) -- (C.north east);
        }
    }
}

\begin{tikzpicture}
\pic (a) {vhsplit={a}{2.0}{6.0}};
\pic[below=10mm of a-box.south] (b) {vhsplit={b}{-3.0}{-4.0}};
\end{tikzpicture}

\end{document}

答え1

画像はノードほどスマートではありません。指定された場所に配置されるのは常に画像の原点です。

必要なのがこれだけであれば、 tabularノード内部に がある通常のノードを使用する方が簡単かもしれません。次の 3 つの方法があります。

  1. 通常のテキストと 2 行 1 列の表形式
    vhsplit
  2. 2行2列の表が1つあり#1\multirow
    vhsplit'
  3. rectangle splitライブラリからshapes.multipart、1 と同様に表形式で再度取得します。
    vhsplit''

表の行はノードの境界に触れる必要があるため、inner seps (デフォルトは .3333em) を 0 に設定し、適切な場所にそのスペースを再度挿入します。

左側部分の垂直配置は多少異なります。ユースケースに最も適したものを選択してください (ソリューションは赤/緑/青の順に色分けされ、 で重ねられていますopacity=.3333)。

ここに画像の説明を入力してください

コード

\documentclass[tikz,border=2mm]{standalone}
\usepackage{hhline}
\usepackage{multirow}
\usetikzlibrary{positioning}
\tikzset{
  vhsplit/.style n args={3}{% text and a tabular
    shape=rectangle, draw, rounded corners, inner sep=+0pt,
    node contents={%
      \setlength{\tabcolsep}{.3333em}%
      \hspxsep#1\hspxsep
      \begin{tabular}{|l@{\hspxsep}}
        \vstysep$#2$\\\hhline{|-}
        \vstysep$#3$%
      \end{tabular}}},
  vhsplit'/.style n args={3}{
    shape=rectangle, draw, rounded corners, inner sep=+0pt,
    node contents={% multirow in a tabular
      \setlength{\tabcolsep}{.3333em}%
      \begin{tabular}{l|l@{\hspxsep}}
        \multirow{2}{*}{#1} &
        \vstysep$#2$\\\hhline{~|-}
        & \vstysep$#3$%
      \end{tabular}}}}
\usetikzlibrary{shapes.multipart}
\tikzset{
  vhsplit''/.style n args={3}{
    shape=rectangle split, rectangle split horizontal, rectangle split parts=2,
    draw, rounded corners, inner sep=+0pt,
    node contents={% two nodeparts and a tabular
      \hspxsep#1\hspxsep\null
      \nodepart{two}\setlength{\tabcolsep}{.3333em}%
      \begin{tabular}{l}
        \vstysep$#2$\\\hline
        \vstysep$#3$
      \end{tabular}}}}
\newcommand*\hspxsep{\hspace{.3333em}}
\newcommand*\vstysep{\rule{0pt}{1.0333em}}
\begin{document}
\begin{tikzpicture}
\node             (a) [vhsplit={a}{ 2.0} {6.0}];
\node[below=of a] (b) [vhsplit={b}{-3.0}{-4.0}];

\tikzset{xshift=2cm}
\node (a)         (a) [vhsplit'={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit'={b}{-3.0}{-4.0}];

\tikzset{xshift=2cm}
\node             (a) [vhsplit''={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit''={b}{-3.0}{-4.0}];
\end{tikzpicture}
\end{document}

出力

ここに画像の説明を入力してください

答え2

これを試して:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}
    
    \tikzset{
        pics/vhsplit/.style n args = {3}{
            code = {
                \node (A) at (0,0) {#1};
                \node[anchor=south west] (B) at (A.east) {#2};
                \node[anchor=north west] (C) at (A.east) {#3};
                \node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {}; 
                \draw (B.north west) -- (C.south west)
                (B.south west) -- (C.north east);
            }
        }
    }

    \begin{tikzpicture}{scale=3} % <-- changed
        \pic (a) {vhsplit={a}{2.0}{6.0}};
        \pic[xshift=0cm,yshift=-1cm] (b) {vhsplit={b}{-3.0}{-4.0}};
    \end{tikzpicture}
    
\end{document}

出力:

ここに画像の説明を入力してください

関連情報