
Wenn ich diesen Algorithmus ausführe, tritt kein Fehler auf, aber wenn ich diesen Algorithmus in meine Datei kombiniere, tritt ein Fehler auf. Bitte geben Sie mir eine Lösung.
\documentclass[border=3mm,preview]{standalone}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{fit}
\newcommand\mcc[1]{\multicolumn{1}{c}{#1}}
\begin{document}
\[
\begin{NiceMatrix}
& M_1 & M_2 & M_3 & M_4 \\
J_1 & 0 & 0.66 & 2 & 0.33 \\
J_2 & 1 & 0 & 1.22 & 0.33 \\
J_3 & 0 & 1 & 2 & 1 \\
J_4 & 2.33 & 0.33 & 1.67 & 0 \\
\CodeAfter
\tikz{
\node (f) [draw, inner xsep=1em, fit=(2-2) (5-5)] {};
\draw[line width=3pt, opacity=0.2]
(2-2 |- f.north) -- (5-2 |- f.south)
(3-2 -| f.west) -- (3-5 -| f.east)
(5-2 -| f.west) -- (5-5 -| f.east);
}
\end{NiceMatrix}
\]
\end{document}
Antwort1
Es ist fast unmöglich, Ihnen zu helfen, wenn Sie keine Informationen zu Ihrem Dokument angeben (welche Dokumentklasse Sie verwenden usw.). Aus diesem Grund verwende ich in meiner Antwort auf Ihre vorherige Frage die standalone
Dokumentklasse und kümmere mich nicht um die Platzierung des bereitgestellten Bildes in Ihrem Dokument.
Wie dem auch sei, mein Code, den Sie für Ihr Bild verwenden, ist unabhängig von der verwendeten Dokumentklasse. Es gibt auch keine Probleme mit überlappendem oder nicht sichtbarem Text über/unter dem Bild. Die Kompilierung erzeugt weder Warnungen noch Fehler. Zum Beispiel:
\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{lipsum}
\begin{document}
\lipsum[11]
\[
\begin{NiceMatrix}
& M_1 & M_2 & M_3 & M_4 \\
J_1 & 0 & 0.66 & 2 & 0.33 \\
J_2 & 1 & 0 & 1.22 & 0.33 \\
J_3 & 0 & 1 & 2 & 1 \\
J_4 & 2.33 & 0.33 & 1.67 & 0 \\
\CodeAfter
\tikz{
\node (f) [draw,
inner xsep=1em, inner ysep=1pt,
fit=(2-2) (5-5)] {};
\draw[line width=3pt, opacity=0.2]
(2-2 |- f.north) -- (5-2 |- f.south)
(3-2 -| f.west) -- (3-5 -| f.east)
(5-2 -| f.west) -- (5-5 -| f.east);
}
\end{NiceMatrix}
\]
\lipsum[12]
\[
\NiceMatrixOptions{%
code-for-first-row = \scriptstyle\color{red},
code-for-first-col = \scriptstyle\color{blue}}
%
\begin{NiceMatrix}[first-row,first-col]
& M_1 & M_2 & M_3 & M_4 \\
J_1 & 0 & 0.66 & 2 & 0.33 \\
J_2 & 1 & 0 & 1.22 & 0.33 \\
J_3 & 0 & 1 & 2 & 1 \\
J_4 & 2.33 & 0.33 & 1.67 & 0 \\
\CodeAfter
\tikz{
\node (f) [draw,
inner xsep=0.8em, inner ysep=1pt, outer sep=2pt, % <---
fit=(1-1) (4-4)] {};
\draw[line width=3pt, opacity=0.2]
(1-1 |- f.north) -- (4-1 |- f.south)
(2-1 -| f.west) -- (2-4 -| f.east)
(4-1 -| f.west) -- (4-4 -| f.east);
}
\end{NiceMatrix}
\]
\end{document}
funktioniert gut. Das zweite Bild ist nur eine etwas ausgefallenere Version des ersten. Es zeigt mehr Möglichkeiten, wie man NiceMatrix
die Umgebung nutzen kann.
Es ist also unklar, was Ihr Problem ist. Es wird mit Sicherheit nicht durch die Lösung verursacht, die in MWE in Ihrer Frage gezeigt wird. Die Ursache Ihres Problems, mit dem Sie konfrontiert sind, wird nicht dadurch verursacht.
Antwort2
Zur Information: Mit neueren Versionen von nicematrix
ist es möglich, diese Konstruktion ohne Transparenz und ohne die Tikz-Bibliothek durchzuführen fit
.
\documentclass[border=3mm,preview]{standalone}
\usepackage{nicematrix,tikz}
\begin{document}
\[
\begin{NiceArray}{|cccc|}[first-col,first-row,last-col]
\CodeBefore
\begin{tikzpicture} [line width = 3pt,lightgray]
\draw (1-|1.5) -- (last-|1.5) ;
\draw (2.5-|1) -- (2.5-|last) ;
\draw (4.5-|1) -- (4.5-|last) ;
\end{tikzpicture}
\Body
& M_1 & M_2 & M_3 & M_4 & \\
\Hline
J_1 & 0 & 0.66 & 2 & 0.33 \\
J_2 & 1 & 0 & 1.22 & 0.33 \\
J_3 & 0 & 1 & 2 & 1 \\
J_4 & 2.33 & 0.33 & 1.67 & 0 \\
\Hline
\end{NiceArray}
\]
\end{document}