TransWikia.com

tikz draw not defined error inside lettrine

TeX - LaTeX Asked on November 26, 2021

Background: I’m using Overleaf as my editor/compiler platform. I don’t have a local compiler due to it being a work computer.

I’m trying to add a little image in the upper left corner of a paragraph. Basically it would act like a drop cap but is a tikzpicture instead of a letter. I want to compile my document without errors but this one is tripping me up. Can someone explain why I’m getting an error and how to fix it?

! Undefined control sequence.
<write> ...ght space (begin {tikzpicture} draw 
                                                  (0,0) rectangle (1.5cm,1.5...
l.18 }{}
        lipsum[1]% error occurs on this line
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

The compiler on Overleaf reports this error which I’m understanding to mean draw is not defined. If you comment out the line with draw on it, the error goes away. Even stranger, as shown in the screenshot and example project, it draws the image anyway.

documentclass{article}

usepackage{lettrine}
usepackage{tikz}

usepackage{lipsum}% for example text

begin{document}

begin{tikzpicture}
    draw (0,0) rectangle (1.5cm,1.5cm);
end{tikzpicture}% this drawing is fine

lettrine[lines=4]{%
begin{tikzpicture}
    draw (0,0) rectangle (1.5cm,1.5cm);
end{tikzpicture}%
}{}lipsum[1]% error occurs on this line

end{document}

screenshot from Overleaf

Here is this example hosted on Overleaf https://www.overleaf.com/read/tpjcwbcpwwmw

One Answer

The main problem comes from leaving the second argument blank. A strut will do. However, to get rid of the error message, use a savebox.

documentclass{article}

usepackage{lettrine}
usepackage{tikz}

usepackage{lipsum}% for example text

newsavebox{letterbox}

begin{document}

savebox{letterbox}{begin{tikzpicture}
    draw (0,0) rectangle (1.5cm,1.5cm);
end{tikzpicture}}%

lettrine[lines=4]{useboxletterbox}{strut}
lipsum[1]

end{document}

Answered by John Kormylo on November 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP