
이 알고리즘을 실행하면 오류가 없지만 이 알고리즘을 내 파일에 결합하면 오류가 발생합니다. 해결책을 주세요.
\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}
답변1
문서에 대한 정보(사용하는 문서 클래스 등)를 제공하지 않으면 도움을 주는 것이 거의 불가능합니다. 결과적으로 이전 질문에 대한 내 대답은 standalone
문서 클래스를 사용하고 문서에 제공된 이미지 배치에 신경 쓰지 않습니다. .
어쨌든 이미지에 사용하는 코드는 사용된 문서 클래스와 독립적입니다. 또한 이미지 위/아래에 텍스트가 겹치거나 보이지 않는 문제도 없습니다. 컴파일해도 경고나 오류가 발생하지 않습니다. 예를 들어:
\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}
잘 작동합니다. 두 번째 이미지는 첫 번째 이미지보다 약간 더 멋진 버전입니다. NiceMatrix
환경을 사용하는 방법에 대한 더 많은 가능성을 보여줍니다.
따라서 귀하의 문제가 무엇인지 불분명합니다. 귀하의 질문에 MWE에 표시된 솔루션으로 인해 발생하지 않은 것이 확실합니다. 당신이 직면한 문제의 원인은 그것으로 인한 것이 아닙니다.
답변2
참고로 최신 버전의 에서는 nicematrix
투명성과 Tikz 라이브러리 없이 해당 구성을 수행할 수 있습니다 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}