1

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., `I\hbox'). 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

3
  • Hello Richard! This is Tom from the Overleaf Support Team. Please note that I removed the overleaf tag as this is not directly Overleaf-related.
    – yo'
    Jul 22, 2020 at 14:06
  • That's fine. I just didn't want to leave out any potentially related information. Jul 22, 2020 at 14:11
  • @yo' this example compiles perfect with a local LaTeX installation on my machine, maybe it is an overleaf issue?
    – TobiBS
    Jul 22, 2020 at 14:15

1 Answer 1

2

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]{\usebox\letterbox}{\strut}
\lipsum[1]

\end{document}
2
  • So many edits to this post. I originally saw the \savebox method and when I tested that on its own it worked without the second argument. Then I saw you edited that out and now edited it back in. Confusing on my side but \savebox seems to do it. Jul 22, 2020 at 14:16
  • I tend to tweak my answers, especially if I don't know WHY they work. Jul 22, 2020 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.