TeX - LaTeX Asked on February 27, 2021
I was trying to create a long horizontal bar where to put the marks of an assessment and I had created the following code.
documentclass{article}
usepackage{tikz}
setlength{parindent}{0pt}
newcommand{TotalMarks}[1]{%
tikzdraw[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}
I cannot understand why it gives an Overfull error:
Overfull hbox (0.79999pt too wide) in paragraph at lines 14--15[][]
How can I fix it?
Thank you for any help you may give me.
There are two things that cause this:
Paragraph indentation. The standard paragraph indentation is added before the tikzpicture, you can disable that for a single line with noindent
, i.e. noindenttikz...
When you draw a line, the bounding box will actually extend by half the line width beyond the end coordinates, as you can see from this example:
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}
The blue line indicates the bounding box.
If you add line cap=rect
, the line will extend to fill that blank space, and you pgf
has the handy macro pgflinewidth
that has the width of the current path. Hence, you can do draw[thick,line cap=rect] (0,0) -- (linewidth-pgflinewidth,0) ...
.
Working example, as egreg mentioned you shouldn't use minimal
(Why should the minimal class be avoided?):
documentclass{article}
usepackage{tikz}
newcommand{TotalMarks}[1]{%
tikzdraw[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}
noindentTotalMarks{2}
end{document}
Correct answer by Torbjørn T. on February 27, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP