노드 매트릭스 - 선 조정

노드 매트릭스 - 선 조정

노드 행렬의 몇 가지 예를 읽은 후 다음 MWE를 작성했습니다.

\documentclass{article}

\usepackage{tikz}\usetikzlibrary{matrix}
\usepackage{booktabs} 

\begin{document}

See the Table \ref{fig:cen2}.

\begin{table}[htb!]
    \caption{My very very very very very long useless caption}
    \label{fig:cen2}
    \begin{tikzpicture}
        \matrix (m) [matrix of nodes,
        nodes in empty cells,
        toprule/.style={%
            execute at end cell={%
                \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north east);%
            }
        },
    bottomrule/.style={%
        execute at end cell={%
            \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }
        },
    midrule/.style={%
        execute at end cell={%
            \draw  (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east)--(\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }

        },
%
        anchor=base,
        row sep    = -\pgflinewidth,
        column sep = -\pgflinewidth,
%
        row 1/.style={nodes={font=\bfseries, align = center}, anchor = south},%toprule = thick
        row 2/.style={anchor = south},
        row 3/.style={anchor = south},
        row 4/.style={anchor = south},
        row 5/.style={anchor = south},
%       
        column 1/.style={nodes={ text width=2.5cm,align=left, font = \small}},
        column 2/.style={nodes={ text width=4.0cm,align=left, font = \small}},
        column 3/.style={nodes={ text width=4.0cm,align=left, font = \small}},
        column 4/.style={nodes={ text width=4.0cm,align=left, font = \small}}%rectangle,draw,
        ] at (0,0)
%
        {%
            Variables & Hypothesis 1 & Hypothesis 2 & Hypothesis 3 \\
            Territorial unit &
            Final destination for receiving waste generated in the municipality &
            Final destination for receiving waste generated in the municipality &
            Final destination to receive the waste generated in the municipality \\
            Index of coverage &
            Maintenance of the urban coverage index, with focus on short term &
            Maintenance of the urban coverage index, focusing on medium term &
            Maintenance of the urban coverage index, with a long-term focus \\
            Garbage Collection with Recovery of Recyclable garbage &
            Increase in the Recovery of Recyclable garbage index in the short term &
            Moderate increase in the recovery of recyclable garbage index with focus on medium term &
            Expectation of implementation of long-term selective collection \\
            Composting of organic waste &
            Adhesion and massive investment in compost disposal final solid organic waste &
            Adhesion and moderate investment in composting final disposal of organic solid waste &
            Investment in composting organic long-term solid waste \\
        };

        \draw [-, very thick] (m-1-1.north west) -- (m-1-4.north east);%linha 1
        \draw [-, thick]      (m-1-4.south east) -- (m-1-1.south west);%linha 2
        \draw [-, thin]       (m-2-1.south west) -- (m-2-4.south east);%linha 3
        \draw [-, thin]       (m-3-1.south west) -- (m-3-4.south east);%linha 4
        \draw [-, thin]       (m-4-1.south west) -- (m-4-4.south east);%linha 5
        \draw [-, thick]      (m-5-1.south west) -- (m-5-4.south east);%linha 6
%       
        \draw[->, color = green,  ultra thick, dashed] (m-2-2.mid) -- ([yshift = -5mm]m-5-2.south);
        \draw[->, color = orange, ultra thick, dashed] (m-2-3.mid) -- ([yshift = -5mm]m-5-3.south);
        \draw[->, color = red,    ultra thick, dashed] (m-2-4.mid) -- ([yshift = -5mm]m-5-4.south);
%       
        \node [below, yshift = -5mm] at (m-5-2.south) {\textcolor{green} {\bfseries Scenario 1}};
        \node [below, yshift = -5mm] at (m-5-3.south) {\textcolor{orange}{\bfseries Scenario 2}};
        \node [below, yshift = -5mm] at (m-5-4.south) {\textcolor{red}   {\bfseries Scenario 3}};
    \end{tikzpicture}
\end{table}

\end{document}

그러나 행렬에는 구부러진 선이 있습니다. 선을 수평으로 조정하는 방법은 무엇입니까?

비뚤어진 선이 있는 행렬

답변1

난 다른 방식으로 테이블을 차릴 텐데...

  • tabularx표준 테이블 환경 사용
  • 수직 점선의 경우 tikzmark라이브러리를 사용하십시오.
  • 셀 내용을 맨 위에 정렬
  • raged2e셀의 텍스트를 더 잘 정렬하려면 패키지를 사용하세요 .
  • 수평 규칙에 사용합니다 booktabs. 여기서는 3개만 사용하겠습니다.
  • makecell테이블 하단의 열 헤더 및 "레이블"에 사용

위의 테이블 코드를 고려하면 훨씬 더 짧고 간단하며 명확해집니다(제 생각에는). 물론 최종 테이블을 얻으려면 코드를 최소한 두 번 컴파일해야 합니다.

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

\documentclass{article}
\usepackage{geometry}

\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, tikzmark}
\usepackage{booktabs, makecell, tabularx}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\usepackage{ragged2e}
\usepackage[labelfont=bf,
            skip=1ex]{caption}

\begin{document}

See the Table \ref{fig:cen2}.
    \begin{table}[htb!]
\caption{My very very very very very long useless caption}
    \label{fig:cen2}
\small
\begin{tabularx}{\linewidth}{>{\RaggedRight}p{25mm} *{3}{>{\RaggedRight}X}}
        \toprule
    \thead{Variables}   &
    \tikzmark{As}\thead{Hypothesis 1}\tikzmark{Ae}  &
    \tikzmark{Bs}\thead{Hypothesis 2}\tikzmark{Be}  &
    \tikzmark{Cs}\thead{Hypothesis 3}\tikzmark{Ce}                      \\
        \midrule
    Territorial unit &
    Final destination for receiving waste generated in the municipality &
    Final destination for receiving waste generated in the municipality &
    Final destination to receive the waste generated in the municipality \\
        \addlinespace
    Index of coverage &
    Maintenance of the urban coverage index, with focus on short term &
    Maintenance of the urban coverage index, focusing on medium term &
    Maintenance of the urban coverage index, with a long-term focus \\
        \addlinespace
    Garbage Collection with Recovery of Recyclable garbage &
    Increase in the Recovery of Recyclable garbage index in the short term &
    Moderate increase in the recovery of recyclable garbage index with focus on medium term &
    Expectation of implementation of long-term selective collection \\
        \addlinespace
    Composting of organic waste &
    Adhesion and massive investment in compost disposal final solid organic waste &
    Adhesion and moderate investment in composting final disposal of organic solid waste &
    Investment in composting organic long-term solid waste \\
        \midrule[\heavyrulewidth]
        \addlinespace
        &
    \tikzmark{AAs}\thead{\textcolor{green}{Scenario 1}}\tikzmark{AAe} &
    \tikzmark{BBs}\thead{\textcolor{orange}{Scenario 2}}\tikzmark{BBe}&
    \tikzmark{CCs}\thead{\textcolor{red}{Scenario 3}}\tikzmark{CCe}
    \end{tabularx}
\begin{tikzpicture}[overlay, remember picture,
line/.style = {draw=#1, line width=1mm, densely dashed, -Straight Barb,
               semitransparent, shorten <=5mm, shorten >=3mm}
                    ]
\draw[line=green]   ($(pic cs:As)!0.5!(pic cs:Ae)$) -- ($(pic cs:AAs)!0.5!(pic cs:AAe)$);
\draw[line=orange]  ($(pic cs:Bs)!0.5!(pic cs:Be)$) -- ($(pic cs:BBs)!0.5!(pic cs:BBe)$);
\draw[line=red]     ($(pic cs:Cs)!0.5!(pic cs:Ce)$) -- ($(pic cs:CCs)!0.5!(pic cs:CCe)$);
\end{tikzpicture}
    \end{table}
\end{document}

답변2

를 추가하여 수정할 수 있습니다 \strut.

\documentclass{article}

\usepackage{tikz}\usetikzlibrary{matrix}
\usepackage{booktabs} 

\begin{document}

See the Table \ref{fig:cen2}.

\begin{table}[htb!]
    \caption{My very very very very very long useless caption}
    \label{fig:cen2}
    \begin{tikzpicture}
        \matrix (m) [matrix of nodes,
        nodes in empty cells,
        toprule/.style={%
            execute at end cell={%
                \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north east);%
            }
        },
    bottomrule/.style={%
        execute at end cell={%
            \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }
        },
    midrule/.style={%
        execute at end cell={%
            \draw  (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east)--(\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }

        },
%
        baseline=base,
        row sep    = -\pgflinewidth,
        column sep = -\pgflinewidth,
%
        row 1/.style={nodes={font=\bfseries\strut, align = center}, anchor = south},%toprule = thick
        row 2/.style={anchor = south},
        row 3/.style={anchor = south},
        row 4/.style={anchor = south},
        row 5/.style={anchor = south},
%       
        column 1/.style={nodes={text width=2.5cm,align=left, font = \small\strut}},
        column 2/.style={nodes={text width=4.0cm,align=left, font = \small\strut}},
        column 3/.style={nodes={text width=4.0cm,align=left, font = \small\strut}},
        column 4/.style={nodes={text width=4.0cm,align=left, font = \small\strut}}%rectangle,draw,
        ] at (0,0)
%
        {%
            Variables & Hypothesis 1 & Hypothesis 2 &
            Hypothesis 3 \\
            Territorial unit &
            Final destination for receiving waste generated in the municipality &
            Final destination for receiving waste generated in the municipality &
            Final destination to receive the waste generated in the municipality \\
            Index of coverage &
            Maintenance of the urban coverage index, with focus on short term &
            Maintenance of the urban coverage index, focusing on medium term &
            Maintenance of the urban coverage index, with a long-term focus \\
            Garbage Collection with Recovery of Recyclable garbage &
            Increase in the Recovery of Recyclable garbage index in the short term &
            Moderate increase in the recovery of recyclable garbage index with focus on medium term &
            Expectation of implementation of long-term selective collection \\
            Composting of organic waste &
            Adhesion and massive investment in compost disposal final solid organic waste &
            Adhesion and moderate investment in composting final disposal of organic solid waste &
            Investment in composting organic long-term solid waste \\
        };

        \draw [-, very thick] (m-1-1.north west) -- (m-1-4.north east);%linha 1
        \draw [-, thick]      (m-1-4.south east) -- (m-1-1.south west);%linha 2
        \draw [-, thin]       (m-2-1.south west) -- (m-2-4.south east);%linha 3
        \draw [-, thin]       (m-3-1.south west) -- (m-3-4.south east);%linha 4
        \draw [-, thin]       (m-4-1.south west) -- (m-4-4.south east);%linha 5
        \draw [-, thick]      (m-5-1.south west) -- (m-5-4.south east);%linha 6
%       
        \draw[->, color = green,  ultra thick, dashed] (m-2-2.mid) -- ([yshift = -5mm]m-5-2.south);
        \draw[->, color = orange, ultra thick, dashed] (m-2-3.mid) -- ([yshift = -5mm]m-5-3.south);
        \draw[->, color = red,    ultra thick, dashed] (m-2-4.mid) -- ([yshift = -5mm]m-5-4.south);
%       
        \node [below, yshift = -5mm] at (m-5-2.south) {\textcolor{green} {\bfseries Scenario 1}};
        \node [below, yshift = -5mm] at (m-5-3.south) {\textcolor{orange}{\bfseries Scenario 2}};
        \node [below, yshift = -5mm] at (m-5-4.south) {\textcolor{red}   {\bfseries Scenario 3}};
    \end{tikzpicture}
\end{table}

\end{document}

\begin{table}[htb!]
    \caption{My very very very very very long useless caption}
    \label{fig:cen2}
    \begin{tikzpicture}
        \matrix (m) [matrix of nodes,
        nodes in empty cells,
        toprule/.style={%
            execute at end cell={%
                \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.north east);%
            }
        },
    bottomrule/.style={%
        execute at end cell={%
            \draw [line cap=rect,#1] (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south west) -- (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }
        },
    midrule/.style={%
        execute at end cell={%
            \draw  (\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east)--(\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn.south east);%
            }

        },
%
        baseline=base,
        row sep    = -\pgflinewidth,
        column sep = -\pgflinewidth,
%
        row 1/.style={nodes={font=\bfseries\strut, align = center}, anchor = south},%toprule = thick
        row 2/.style={anchor = south},
        row 3/.style={anchor = south},
        row 4/.style={anchor = south},
        row 5/.style={anchor = south},
%       
        column 1/.style={nodes={ text width=2.5cm,align=left, font = \small\strut}},
        column 2/.style={nodes={ text width=4.0cm,align=left, font = \small\strut}},
        column 3/.style={nodes={ text width=4.0cm,align=left, font = \small\strut}},
        column 4/.style={nodes={ text width=4.0cm,align=left, font = \small\strut}}%rectangle,draw,
        ] at (0,0)
%
        {%
            Variables & Hypothesis 1 & Hypothesis 2 &
            Hypothesis 3 \\
            Territorial unit &
            Final destination for receiving waste generated in the municipality &
            Final destination for receiving waste generated in the municipality &
            Final destination to receive the waste generated in the municipality \\
            Index of coverage &
            Maintenance of the urban coverage index, with focus on short term &
            Maintenance of the urban coverage index, focusing on medium term &
            Maintenance of the urban coverage index, with a long-term focus \\
            Garbage Collection with Recovery of Recyclable garbage &
            Increase in the Recovery of Recyclable garbage index in the short term &
            Moderate increase in the recovery of recyclable garbage index with focus on medium term &
            Expectation of implementation of long-term selective collection \\
            Composting of organic waste &
            Adhesion and massive investment in compost disposal final solid organic waste &
            Adhesion and moderate investment in composting final disposal of organic solid waste &
            Investment in composting organic long-term solid waste \\
        };

        \draw [-, very thick] (m-1-1.north west) -- (m-1-4.north east);%linha 1
        \draw [-, thick]      (m-1-4.south east) -- (m-1-1.south west);%linha 2
        \draw [-, thin]       (m-2-1.south west) -- (m-2-4.south east);%linha 3
        \draw [-, thin]       (m-3-1.south west) -- (m-3-4.south east);%linha 4
        \draw [-, thin]       (m-4-1.south west) -- (m-4-4.south east);%linha 5
        \draw [-, thick]      (m-5-1.south west) -- (m-5-4.south east);%linha 6
%       
        \draw[->, color = green,  ultra thick, dashed] (m-2-2.mid) -- ([yshift = -5mm]m-5-2.south);
        \draw[->, color = orange, ultra thick, dashed] (m-2-3.mid) -- ([yshift = -5mm]m-5-3.south);
        \draw[->, color = red,    ultra thick, dashed] (m-2-4.mid) -- ([yshift = -5mm]m-5-4.south);
%       
        \node [below, yshift = -5mm] at (m-5-2.south) {\textcolor{green} {\bfseries Scenario 1}};
        \node [below, yshift = -5mm] at (m-5-3.south) {\textcolor{orange}{\bfseries Scenario 2}};
        \node [below, yshift = -5mm] at (m-5-4.south) {\textcolor{red}   {\bfseries Scenario 3}};
    \end{tikzpicture}
\end{table}

\end{document}

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

그러나 나는 당신이 열 방향과 행 방향 지시문을 겹쳐 놓기 때문에 (동면하는 Zarko처럼 ;-) 나도 길을 잃었다는 것을 인정해야 합니다. 아래쪽 셀을 수정하기 전에 어떤 정렬을 목표로 하고 있는지 알아야 합니다.

답변3

패키지를 제안하려고 했으나 matrixcells이 사이트에서 해당 패키지를 촉발한 원래 질문을 검색하던 중 누군가가 해당 패키지의 일부 문제를 수정했다는 사실을 발견하여 다음을 사용하는 것이 좋습니다.matrix.skeleton패키지(에서y축에만 있는 매트릭스셀 문제) 대신에.

사용하지 않는 코드를 조금 제거했습니다.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/415345/86}

\usepackage{tikz}\usetikzlibrary{matrix}
\usepackage{booktabs}
\usetikzlibrary{matrix.skeleton}

\begin{document}

See the Table \ref{fig:cen2}.

\begin{table}[htb!]
    \caption{My very very very very very long useless caption}
    \label{fig:cen2}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes,
  nodes in empty cells,
  label skeleton,
%
        anchor=base,
        row sep    = -\pgflinewidth,
        column sep = -\pgflinewidth,
%
        row 1/.style={nodes={font=\bfseries, align = center}, anchor = south},%toprule = thick
        row 2/.style={anchor = south},
        row 3/.style={anchor = south},
        row 4/.style={anchor = south},
        row 5/.style={anchor = south},
%       
        column 1/.style={nodes={ text width=2.5cm,align=left, font = \small}},
        column 2/.style={nodes={ text width=4.0cm,align=left, font = \small}},
        column 3/.style={nodes={ text width=4.0cm,align=left, font = \small}},
        column 4/.style={nodes={ text width=4.0cm,align=left, font = \small}}%rectangle,draw,
        ] at (0,0)
%
        {%
            Variables & Hypothesis 1 & Hypothesis 2 & Hypothesis 3 \\
            Territorial unit &
            Final destination for receiving waste generated in the municipality &
            Final destination for receiving waste generated in the municipality &
            Final destination to receive the waste generated in the municipality \\
            Index of coverage &
            Maintenance of the urban coverage index, with focus on short term &
            Maintenance of the urban coverage index, focusing on medium term &
            Maintenance of the urban coverage index, with a long-term focus \\
            Garbage Collection with Recovery of Recyclable garbage &
            Increase in the Recovery of Recyclable garbage index in the short term &
            Moderate increase in the recovery of recyclable garbage index with focus on medium term &
            Expectation of implementation of long-term selective collection \\
            Composting of organic waste &
            Adhesion and massive investment in compost disposal final solid organic waste &
            Adhesion and moderate investment in composting final disposal of organic solid waste &
            Investment in composting organic long-term solid waste \\
        };

        \draw [-, very thick] (m-row-1.north west) -- (m-row-1.north east);%linha 1
        \draw [-, thick]      (m-row-2.north west) -- (m-row-2.north east);%linha 2
        \draw [-, thin]       (m-row-3.north west) -- (m-row-3.north east);%linha 3
        \draw [-, thin]       (m-row-4.north west) -- (m-row-4.north east);%linha 4
        \draw [-, thin]       (m-row-5.north west) -- (m-row-5.north east);%linha 5
        \draw [-, thick]      (m-row-5.south west) -- (m-row-5.south east);%linha 6
%       
        \draw[->, color = green,  ultra thick, dashed] (m-2-2.mid) -- ([yshift = -5mm]m-5-2.south);
        \draw[->, color = orange, ultra thick, dashed] (m-2-3.mid) -- ([yshift = -5mm]m-5-3.south);
        \draw[->, color = red,    ultra thick, dashed] (m-2-4.mid) -- ([yshift = -5mm]m-5-4.south);
%       
        \node [below, yshift = -5mm] at (m-5-2.south) {\textcolor{green} {\bfseries Scenario 1}};
        \node [below, yshift = -5mm] at (m-5-3.south) {\textcolor{orange}{\bfseries Scenario 2}};
        \node [below, yshift = -5mm] at (m-5-4.south) {\textcolor{red}   {\bfseries Scenario 3}};
    \end{tikzpicture}
\end{table}

\end{document}

행렬의 직선

관련 정보