Spanish Characters in LaTeX: ñ, Accents, and Special Letters
Date Published

Spanish Characters in LaTeX
Write Spanish documents in LaTeX with proper accents and special characters.
Quick answer: How do you write Spanish in LaTeX? Save the file as UTF-8 and type á, é, í, ó, ú, ü, ñ, ¿ and ¡ directly. LaTeX has read UTF-8 by default since 2018, so \usepackage[utf8]{inputenc} is only needed on older installations (keeping it is harmless). Add \usepackage[T1]{fontenc} so accented words hyphenate and copy correctly from the PDF, and \usepackage[spanish]{babel} for Spanish hyphenation, captions and dates. Without UTF-8, write \~n for ñ, \'a for á, \"u for ü, ?` for ¿ and !` for ¡.
Spanish in LaTeX: Accents, ñ, ¿ and babel
A complete Spanish document for pdfLaTeX, showing both ways to enter each character (with XeLaTeX or LuaLaTeX, drop inputenc and fontenc and load fontspec instead):
1\documentclass{article}2\usepackage[utf8]{inputenc} % legacy: UTF-8 is the default since LaTeX 20183\usepackage[T1]{fontenc} % accented glyphs, hyphenation, copy-paste4\usepackage[spanish]{babel} % Spanish hyphenation, captions and \today5\begin{document}6\section{Introducción}7% Typed directly (UTF-8):8El niño pidió un café en España. ¿Cómo estás? ¡Hola!910% The same text with LaTeX commands (works in any encoding):11El ni\~no pidi\'o un caf\'e en Espa\~na. ?`C\'omo est\'as? !`Hola!1213Diéresis: ping\"uino, cig\"ue\~na. Mayúsculas: \'A \'E \'I \'O \'U \~N.1415Fecha: \today. Comillas: <<texto>>. % babel spanish turns << >> into guillemets16\end{document}
Try this in Octree — free LaTeX editor with AI, compiles in your browser
Character | LaTeX command | Notes |
|---|---|---|
á é í ó ú |
| Acute accents; |
Á É Í Ó Ú |
| Uppercase accents are kept in Spanish |
ñ Ñ |
| Tilde (eñe) |
ü Ü |
| Diaeresis, as in pingüino |
¿ |
| Question mark then backtick |
¡ |
| Exclamation mark then backtick |
« » |
| << >> needs babel spanish |
Input Encoding
First, enable proper encoding:
\usepackage[utf8]{inputenc} — for pdfLaTeX
Or use XeLaTeX/LuaLaTeX which handle UTF-8 natively.
The Spanish babel Package
\usepackage[spanish]{babel}
This provides: - Correct hyphenation - Spanish quotation marks - Translated captions ("Capítulo", "Figura", etc.)
Special Characters
The ñ Character
ñ — type directly (with UTF-8)
\~n — explicit command
\~N — uppercase Ñ
Acute Accents (áéíóú)
\'a — á \'e — é \'i — í (or \'{\i} for dotless i) \'o — ó \'u — ú
Or type directly with UTF-8: á é í ó ú
Diaeresis (ü)
\"u — ü
Used in: cigüeña, pingüino, vergüenza
Uppercase Accents
\'A — Á \'E — É \'I — Í \'O — Ó \'U — Ú
Inverted Punctuation
Inverted Question Mark
Type a question mark then a backtick (?`) — ¿
\textquestiondown — explicit command
Inverted Exclamation
Type an exclamation mark then a backtick (!`) — ¡
\textexclamdown — explicit command
Usage
¿Cómo estás?
¡Hola!
Spanish Quotation Marks
With babel spanish:
<<texto>> — renders as «texto»
Or use:
\guillemotleft texto\guillemotright
Example Document
\documentclass{article} \usepackage[utf8]{inputenc} \usepackage[spanish]{babel}
\begin{document}
\section{Introducción}
El español es una lengua romance. La letra ñ es única del español.
¿Cuántos años tienes?
¡Qué bonito día!
\end{document}
Common Spanish Words
- año (year) - niño (child) - España (Spain) - pequeño (small) - mañana (tomorrow/morning) - señor (mister) - cañón (canyon)
Babel Spanish Options
\usepackage[spanish,es-noquoting]{babel}
\usepackage[spanish,es-tabla]{babel} — "Tabla" instead of "Cuadro"
\usepackage[spanish,es-noindentfirst]{babel} — no first paragraph indent
Date Format
With babel spanish, dates format as:
\today → 25 de diciembre de 2025
Chapter and Section Names
Automatically translated: - Chapter → Capítulo - Figure → Figura - Table → Tabla/Cuadro - Contents → Índice general - References → Referencias
XeLaTeX/LuaLaTeX Approach
For full Unicode support:
\documentclass{article} \usepackage{fontspec} \usepackage[spanish]{babel} \setmainfont{Latin Modern Roman}
No inputenc needed—type characters directly.
Tips
1. Use UTF-8 encoding for source files 2. Include babel for proper hyphenation 3. Type accents directly when possible 4. Test quotation marks render correctly
Spanish in LaTeX FAQ
How do I type ñ in LaTeX?
Type ñ directly in a UTF-8 file, or write \~n (and \~N for Ñ). Load \usepackage[T1]{fontenc} with pdfLaTeX so words containing ñ hyphenate and copy correctly.
How do I write accents in LaTeX?
Type the accented letter directly (UTF-8), or use the accent commands: \'a for á, \"u for ü, \~n for ñ. Inside the tabbing environment use \a' instead of \'.
Do I still need \usepackage[utf8]{inputenc}?
Not with a LaTeX release from 2018 or later: pdfLaTeX reads UTF-8 by default, and XeLaTeX and LuaLaTeX always have. The line does no harm, so templates often keep it for older installations.
How do I write ¿ and ¡ in LaTeX?
Type them directly, or type ?` and !` (the mark, then a backtick), which LaTeX turns into ¿ and ¡. The commands \textquestiondown and \textexclamdown also work.
Why does babel spanish write "Cuadro" instead of "Tabla"?
Traditional Spanish typography calls tables "cuadros". Load babel with \usepackage[spanish,es-tabla]{babel} to get "Tabla" and "Índice de tablas".
Write Spanish Documents with Octree
Octree supports international text:
- Full UTF-8 support - Spanish language templates - Preview accents correctly - Export perfect PDFs
Try it at https://useoctree.com
Try this in Octree — free LaTeX editor with AI, compiles in your browser

Learn LaTeX in 2025 with modern AI-powered tools. From setup to advanced tips, this guide helps you write papers, resumes, and documents like a pro.

Introducing Octree — an open-source AI-LaTeX editor with smart BibTeX management, TikZ visualization, and AI-assisted writing.

Discover how Octree compares to Overleaf — from AI-assisted LaTeX writing and TikZ/BibTeX automation to open-source flexibility and offline editing for researchers.