설명할 수 없는 과잉 상자

설명할 수 없는 과잉 상자

평가 점수를 표시할 긴 가로 막대를 만들려고 하다가 다음 코드를 만들었습니다.

\documentclass{article}

\usepackage{tikz}
\setlength{\parindent}{0pt}

\newcommand{\TotalMarks}[1]{%
    \tikz\draw[thick]
    (0,0) -- (\linewidth,0) -- 
    ++(0,2em) -- ++(-2em,0) -- 
    ++(0,-2em) node[pos=0.6,left] 
        {\makebox[2.9cm]{\textbf{Total: #1 marks}\hfill}};}

\begin{document}
\TotalMarks{2}
\end{document}

Overfull 오류가 발생하는 이유를 이해할 수 없습니다.

Overfull \hbox (0.79999pt too wide) in paragraph at lines 14--15[][] 

어떻게 해결할 수 있나요?

나에게 도움을 주셔서 감사합니다.

답변1

이 문제의 원인은 두 가지입니다.

  1. 단락 들여쓰기. 표준 단락 들여쓰기는 tikzpicture 앞에 추가됩니다. \noindent즉, 한 줄에 대해 이를 비활성화할 수 있습니다.\noindent\tikz...

  2. 선을 그릴 때 경계 상자는 실제로 다음 예에서 볼 수 있듯이 끝 좌표를 넘어 선 너비의 절반만큼 확장됩니다.

     \documentclass[border=5mm]{standalone}
     \usepackage{tikz}
     \begin{document}
    
     \begin{tikzpicture}
       \draw [line width=5mm] (0,0) -- (1,0);
       \draw [very thin, red] (0,-0.5) -- (0,0.5);
    
       \draw [thin, blue] (current bounding box.south east) rectangle (current bounding box.north west);
     \end{tikzpicture}
     \end{document}
    

여기에 이미지 설명을 입력하세요

파란색 선은 경계 상자를 나타냅니다.

을 추가하면 line cap=rect해당 빈 공간을 채울 수 있도록 줄이 확장되며 현재 경로의 너비를 갖는 pgf편리한 매크로를 갖게 됩니다 . \pgflinewidth그러므로 당신은 할 수 있습니다 \draw[thick,line cap=rect] (0,0) -- (\linewidth-\pgflinewidth,0) ....

실제 예에서는 egreg가 언급했듯이 minimal(왜 최소 수업을 피해야 합니까?):

\documentclass{article}

\usepackage{tikz}

\newcommand{\TotalMarks}[1]{%
    \tikz\draw[thick,line cap=rect]
    (0,0) -- (\linewidth-\pgflinewidth,0) -- 
    ++(0,2em) -- ++(-2em,0) -- 
    ++(0,-2em) node[pos=0.6,left] 
        {\makebox[2.9cm]{\textbf{Total: #1 marks}\hfill}};}

\begin{document}
\noindent\TotalMarks{2}
\end{document}

관련 정보