![tikzpicture 环境中的 \hdashline](https://linux22.com/image/436406/tikzpicture%20%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%20%5Chdashline.png)
这段代码让我有点困惑。我想要一个 \hdashline,但 Overleaf 却报错,为什么?
我的代码
\documentclass{article}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,top=1.5cm,bottom=1.5cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz-cd}
\usepackage{color}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{stmaryrd}
\usepackage{stix}
\usepackage{xcolor}
\usepackage[customcolors,shade]{hf-tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc,matrix,backgrounds}
\begin{document}
\subsection{Ancora su Sarrus}
\begin{tikzpicture}[baseline=(A.center)]
\tikzset{Barr/.style = {opacity=.4,line width=4 mm,line cap=round,color=#1},
Sigp/.style = {circle, fill=blue, fill opacity=0.4, text opacity=1,
minimum size=4mm, left, inner sep=0pt,
node contents={$+$}},
Sigm/.style = {Sigp,fill=red, node contents={\vphantom{+}$-$}},
Prod/.style = {rounded corners=5pt,
fill=#1, fill opacity=0.4, text opacity=1, inner sep=2pt, right},
}
% the matrices
\matrix (A) [matrix of math nodes,
column sep=1ex,
row sep=1ex
]
{ a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33} \\ \hline %I'd like a \hdashline, but Overleaf gives me an error, why?
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
};
\draw[semithick] (A-1-1.north west) -- (A-3-1.south west)
(A-1-3.north east) -- (A-3-3.south east);
\draw [Barr=blue] (A-1-1.north west) node[Sigp] to (A-3-3.south east) node[Prod=blue]{$a_{11}\cdot a_{22}\cdot a_{33}$}
(A-2-1.north west) node[Sigp] to (A-4-3.south east) node[Prod=blue]{$a_{21}\cdot a_{32}\cdot a_{13}$}
(A-3-1.north west) node[Sigp] to (A-5-3.south east) node[Prod=blue]{$a_{31}\cdot a_{12}\cdot a_{23}$};
\draw [Barr=red] (A-3-1.south west) node[Sigm] to (A-1-3.north east) node[Prod=red]{$a_{31}\cdot a_{22}\cdot a_{13}$}
(A-4-1.south west) node[Sigm] to (A-2-3.north east) node[Prod=red]{$a_{11}\cdot a_{32}\cdot a_{23}$}
(A-5-1.south west) node[Sigm] to (A-3-3.north east) node[Prod=red]{$a_{21}\cdot a_{12}\cdot a_{33}$};
\end{tikzpicture}
\end{document}
我已经加载了我正在使用的所有软件包。(我使用这些软件包是因为我正在写一本线性代数的书)非常感谢您的帮助!
答案1
节点矩阵是一张 tikz 图片,您可以在节点之间绘制任何 tikz 路径,我在您表示想要虚线的地方添加了一条绿色虚线。
\documentclass{article}
\usepackage[italian]{babel}
%%% default \usepackage[utf8]{inputenc}
\usepackage[a4paper,top=1.5cm,bottom=1.5cm,left=2cm,right=2cm]{geometry}
\usepackage{tikz-cd}
%%% xcolor \usepackage{color}
%%% mathtools \usepackage{amsmath}
\usepackage{mathtools}
%%% stix2 (mostly) \usepackage{stmaryrd}
\usepackage{stix2}
\usepackage{xcolor}
\usepackage[customcolors,shade]{hf-tikz}
\usepackage{nicematrix}
\usetikzlibrary{calc,matrix,backgrounds}
\begin{document}
\subsection{Ancora su Sarrus}
\begin{tikzpicture}[baseline=(A.center)]
\tikzset{Barr/.style = {opacity=.4,line width=4 mm,line cap=round,color=#1},
Sigp/.style = {circle, fill=blue, fill opacity=0.4, text opacity=1,
minimum size=4mm, left, inner sep=0pt,
node contents={$+$}},
Sigm/.style = {Sigp,fill=red, node contents={\vphantom{+}$-$}},
Prod/.style = {rounded corners=5pt,
fill=#1, fill opacity=0.4, text opacity=1, inner sep=2pt, right},
}
% the matrices
\matrix (A) [matrix of math nodes,
column sep=1ex,
row sep=1ex
]
{ a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33} \\ %\hline %I'd like a \hdashline, but Overleaf gives me an error, why?
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
};
\draw[semithick] (A-1-1.north west) -- (A-3-1.south west)
(A-1-3.north east) -- (A-3-3.south east);
\draw [Barr=blue] (A-1-1.north west) node[Sigp] to (A-3-3.south east) node[Prod=blue]{$a_{11}\cdot a_{22}\cdot a_{33}$}
(A-2-1.north west) node[Sigp] to (A-4-3.south east) node[Prod=blue]{$a_{21}\cdot a_{32}\cdot a_{13}$}
(A-3-1.north west) node[Sigp] to (A-5-3.south east) node[Prod=blue]{$a_{31}\cdot a_{12}\cdot a_{23}$};
\draw [Barr=red] (A-3-1.south west) node[Sigm] to (A-1-3.north east) node[Prod=red]{$a_{31}\cdot a_{22}\cdot a_{13}$}
(A-4-1.south west) node[Sigm] to (A-2-3.north east) node[Prod=red]{$a_{11}\cdot a_{32}\cdot a_{23}$}
(A-5-1.south west) node[Sigm] to (A-3-3.north east) node[Prod=red]{$a_{21}\cdot a_{12}\cdot a_{33}$};
\draw [color=green, dashed] (A-3-1.south west) to (A-3-3.south east);
\end{tikzpicture}
\end{document}