ラテックスの配合

ラテックスの配合

。
このアルゴリズムを実行するとエラーは発生しませんが、このアルゴリズムをファイルに結合するとエラーが発生します。解決策を教えてください。

\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}

正常に動作します。2 番目の画像は最初の画像よりわずかに派手なバージョンですが、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}

上記コードの出力

関連情報