带有“内部”边框线的 Tikz 矩阵

带有“内部”边框线的 Tikz 矩阵

我应该如何编写乳胶代码,以便tikz两列矩阵有一条内部垂直线(左列和右列之间的边界)和一条水平线(第一行和第二行之间的边界)?请参阅下面附加的屏幕截图。

现在,我的代码是:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{matrix}

\begin{document}

\lipsum[1]

\begin{figure}[!ht]
    \centering
    \begin{tikzpicture}
    \matrix[
        matrix of nodes,
        every node/.style={
            draw, 
            minimum width=2in, minimum height=.3in,
            },
        column 1/.style={text width=2in,align=left},
        column 2/.style={text width=2in,align=left},
        row 1/.style={align=center},
        row 2/.style={align=left},
    ]
    {
    \textbf{Assets} & \textbf{Liabilities \& Net Worth} \\
    Financial Assets ($FA$) & Financial Liabilities ($FL$) \\
    \hspace{.3in}$FA$, domestic MoU & \hspace{.3in}$FL$, domestic MoU \\
    \hspace{.3in}$FA$, foreign MoU & \hspace{.3in}$FL$, foreign MoU \\
    Non-Financial Assets ($NFA$) & Net Worth ($NW$) \\
    Total Assets ($FA+NFA$) & Total Liabilities ($FL+NW$) \\
    };
    \end{tikzpicture}
    \caption{Typical balance sheet}
    \label{fig:tbs}
\end{figure}

\lipsum[1]
  
\end{document}

在此处输入图片描述

答案1

使用表格要简单得多,特别是如果您使用tabularray@projetmbc 在他的评论中所建议的包:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}

\usepackage{tabularray}

\begin{document}
\lipsum[1]
    \begin{figure}[!ht]
    \centering
\begin{tblr}{colspec = {l l},
             row{1}  = {c, font=\bfseries},
             hline{2} = 0.8pt, vline{2} = 0.8pt
             }
Assets                      &   Liabilities \& Net Wort         \\
Financial Assets ($FA$)     &   Financial Liabilities ($FL$)    \\
\quad   $FA$, domestic MoU  &   \quad   $FL$, domestic MoU      \\
\quad   $FA$, foreign MoU   &   \quad   $FL$, foreign MoU       \\
Non-Financial Assets ($NFA$)&   Net Worth ($NW$)                \\
Total Assets ($FA+NFA$)     & Total Liabilities ($FL+NW$) 
\end{tblr}
    \caption{Typical balance sheet}
    \label{fig:tbs}
    \end{figure}
\lipsum[2]
\end{document}

在此处输入图片描述

附录:
如果出于某种原因,你更喜欢绘制表格,此时使用matrixTiZ 库,然后尝试以下 MWE:

\documentclass[10pt,a4paper]{article}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
\lipsum[1]
    \begin{figure}[!ht]
    \centering
\begin{tikzpicture}
\matrix (m) [matrix of nodes,
             nodes = {text width=1.8in, minimum height=.2in, align=left},
             column sep=1em,
             row 1/.style={align=center, font=\bfseries},
            ]
{
Assets                      &   Liabilities \& Net Wort         \\
Financial Assets ($FA$)     &   Financial Liabilities ($FL$)    \\
\quad   $FA$, domestic MoU  &   \quad   $FL$, domestic MoU      \\
\quad   $FA$, foreign MoU   &   \quad   $FL$, foreign MoU       \\
Non-Financial Assets ($NFA$)&   Net Worth ($NW$)                \\
Total Assets ($FA+NFA$)     & Total Liabilities ($FL+NW$)       \\
    };
\draw[semithick]    (m-1-2.south -| m.west) -- (m-1-2.south -| m.east)
                    (m.north) -- (m.south);              
\end{tikzpicture}
\caption{Typical balance sheet}
\label{fig:tbs}
    \end{figure}
\lipsum[2]
\end{document}

结果图与之前类似:

在此处输入图片描述

相关内容