How to Fix “File Ended While Scanning Use of \@imakebox”
At a glance
- 1. Find the box command
Look above the reported line for the most recent \makebox or \framebox command.
- 2. Check its arguments
Match every opening brace and square bracket, and check that comments have not hidden a closing brace.
- 3. Compile a small test
Temporarily remove nearby code, then restore it piece by piece to find where the argument is left open.
- 4. Verify the fix
Compile the complete document again and check that the box content and alignment are as intended.
The message “File ended while scanning use of \@imakebox” means LaTeX reached the end of the input while it was still reading an argument for an internal box-making command. The internal name is usually a clue that a \makebox or \framebox command is involved; you normally should not call \@imakebox yourself.
The most common cause is an opening brace without a matching closing brace. The mistake may be several lines before the end of the file, so inspect the box command and the code immediately around it rather than adding a brace at the final line automatically.
What \makebox expects
A standard \makebox has this form:
\makebox[width][position]{content}
The width and position arguments are optional. The braces around content are required. For example, \makebox[4cm][c]{Centered text} creates a box 4 cm wide and centers its content. \framebox has a similar argument structure, but draws a frame around the box.
If LaTeX does not find the end of the required content argument, it keeps scanning subsequent text. When it reaches the end of the file without finding the closing delimiter, it reports that it was still scanning the internal \@imakebox command.
A minimal working example
This complete document uses \makebox correctly and needs no extra packages:
\documentclass{article}
\begin{document}
A centered label: \makebox[4cm][c]{Centered text}.
\end{document}
Compare it with a command that has an unclosed content argument:
\makebox[4cm][c]{Centered text
The opening { has no matching }. In a real document, LaTeX may continue reading many lines before it reports the error at the end of the file.
How to locate the mistake
- Look above the reported location. Search backward for the nearest
\makeboxor\framebox. The message points to where LaTeX ran out of input, not necessarily to the line where the delimiter was omitted. - Match delimiters. Check that each
{has a corresponding}and each optional[has a corresponding]. Pay particular attention to box commands with both optional arguments and a required braced argument. - Check comments. A percent sign begins a comment that continues to the end of that physical line. For example, in
\makebox{Text % }, the closing brace is commented out, so LaTeX never reads it. - Inspect surrounding macros. If the box command is inside a custom command or environment, check the definition and its arguments too. An unmatched delimiter may be in the wrapper rather than in the visible
\makeboxcall. - Isolate the code. Temporarily comment out the suspected box command or nearby block. If the error disappears, restore the code in small pieces until the problematic argument is identified.
Common mistakes
- Adding a closing brace at the end without checking the structure. This can hide the immediate error while making the box contain unrelated material, or create a different grouping problem. Close the argument where it belongs.
- Treating the last line number as the source. TeX often notices an unfinished argument only when it reaches the end of the file.
- Overlooking a comment. A closing brace after
%on the same line is ignored. Move the brace before the percent sign or onto a later, uncommented line. - Confusing the internal command with the command to edit.
\@imakeboxis an implementation detail in normal LaTeX documents. Look for user-level commands such as\makeboxand\frameboxfirst.
If no box command is obvious, reduce the document to a small example and add sections back gradually. Also check for an unclosed group or macro argument that contains a box command; the apparent location of the error can be downstream from the original mismatch.
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.