配製乳膠

配製乳膠

。
當我運行這個演算法時沒有錯誤,但是當我將此演算法合併到我的文件中時,會發生錯誤。請給我一個解決方案。

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

上述程式碼的輸出

相關內容