Skip to main content
v2026.11,858 entries · CC-BY 4.0
LAC HealthMedical Supply Distributor100,000+ medical supplies. 48-hour critical dispatch.Ships from 8 regional U.S. hubs. Net-30 terms for verified institutional accounts.Shop lac.us CodeCASRAIlac.us

Number Line in LaTeX: TikZ Syntax and Axis Setup

Learn how to draw a number line in LaTeX using TikZ, including step-by-step axis commands, automated tick loops, interval markers, and paper figure scaling.

Written and maintained by CASRAI Editorial Board

Last updated

Drawing an accurate 1D coordinate axis or number line in LaTeX is a frequent requirement in academic research papers, working papers, lecture notes, and methodology appendices. While authors often rely on external bitmap images, generating number lines directly in LaTeX preserves sharp vector fidelity, maintains consistent document typography, and simplifies revisions.

What it is used for in research

In quantitative and formal research, a number line visualizes one-dimensional relationships along the real numbers. Researchers across economics, mathematics, biostatistics, and psychology commonly use number lines for several distinct analytical tasks:

  • Hypothesis testing and critical regions: Illustrating rejection thresholds, p-value boundaries, and confidence intervals around null hypotheses.
  • Mathematical inequalities and interval subsets: Visually distinguishing between open, half-open, and closed intervals, such as displaying the set x ∈ [−2, 3) with precise endpoint conventions.
  • Measurement scales and psychometrics: Demonstrating score ranges, Likert scale benchmarks, or cutoff thresholds in experimental protocols.
  • Convergence and error bounds: Plotting algorithm approximations, truncation bounds, or discretization grids.

A common point of confusion for researchers is the native LaTeX command numberline. In standard LaTeX2e, numberline{...} is an internal macro used exclusively by contentsline to format section, figure, and table numbers within table of contents (.toc) and list files. It formats text within a box of fixed width and does not draw coordinate axes or mathematical diagrams. To produce a graphical number line, researchers use the PGF/TikZ graphics engine or dedicated plotting libraries integrated with LaTeX figure environments and LaTeX set notation.

Install or access

The standard tool for drawing number lines in modern LaTeX is TikZ (a recursive acronym for “TikZ ist kein Zeichenprogramm”), built on the underlying Portable Graphics Format (PGF) engine developed by Till Tantau and Christian Feuersänger.

  • TeX Live and MacTeX: TikZ is included in all standard installations under the texlive-pictures collection. No manual downloading is required.
  • MiKTeX: TikZ is pre-installed in the complete distribution. If using the basic installer, MiKTeX automatically downloads the pgf package upon first compilation when on-the-fly package installation is enabled.
  • Cloud and Collaborative Editors: Online platforms such as Overleaf and modern collaborative LaTeX editors have TikZ pre-configured and immediately accessible in standard compilation pipelines.

To enable TikZ in any LaTeX document, add the package declaration to your document preamble:

usepackage{tikz}
usetikzlibrary{arrows.meta}

The optional arrows.meta library provides modern, configurable arrowheads suitable for scientific publication standards.

Step-by-step task

Follow these numbered steps to build a complete, publication-ready number line with labeled tick marks and inequality intervals.

1. Initialize the TikZ environment

All TikZ drawing operations take place within the tikzpicture environment. Ensure each drawing instruction terminates with a semicolon (;), which signals the end of a path statement to the PGF parser:

begin{tikzpicture}
    % Drawing statements go here
end{tikzpicture}

2. Draw the horizontal coordinate axis

Create the main horizontal line using the draw command. Specify coordinates as (x, y) pairs. By default, TikZ treats numbers as centimeters unless explicit units (such as pt or mm) are supplied:

draw[<->, thick] (-5.5, 0) -- (5.5, 0);

The option [<->, thick] adds bidirectional arrows representing continuity toward negative and positive infinity while giving the axis a clean publication line weight.

3. Automate tick marks and numbers with foreach

Instead of manually coding individual tick lines, use the foreach loop provided by the bundled pgffor package. The ellipsis syntax allows compact range definition:

foreach x in {-5, -4, ..., 5} {
    draw[thick] (x, 0.15) -- (x, -0.15);
    node[below=2pt] at (x, -0.15) {small $x$};
}

This loop places a vertical line segment 0.3 cm in height centered on the axis at each integer coordinate and anchors the math-mode coordinate label directly beneath it.

4. Overlay interval segments and boundary markers

To visualize a mathematical interval or parameter range—for example, the half-open interval [−2, 3)—overlay a colored segment and point markers:

% Highlighted segment
draw[blue, ultra thick] (-2, 0) -- (3, 0);

% Inclusive endpoint at x = -2 (solid filled circle)
filldraw[blue] (-2, 0) circle (2.5pt);

% Exclusive endpoint at x = 3 (open hollow circle)
draw[blue, thick, fill=white] (3, 0) circle (2.5pt);

% Mathematical notation label above the line
node[above=8pt, blue] at (0.5, 0) {$-2 le x < 3$};

5. Wrap in an academic figure float

In journal manuscripts, place the diagram within a standard float environment to manage positioning, captioning, and cross-referencing alongside aligned mathematical equations in LaTeX and LaTeX matrix formatting:

begin{figure}[htbp]
centering
begin{tikzpicture}[scale=0.9, every node/.transform shape]
    draw[<->, thick] (-5.5, 0) -- (5.5, 0);
    foreach x in {-5, -4, ..., 5} {
        draw[thick] (x, 0.15) -- (x, -0.15);
        node[below=2pt] at (x, -0.15) {small $x$};
    }
    draw[blue, ultra thick] (-2, 0) -- (3, 0);
    filldraw[blue] (-2, 0) circle (2.5pt);
    draw[blue, thick, fill=white] (3, 0) circle (2.5pt);
    node[above=8pt, blue] at (0.5, 0) {$-2 le x < 3$};
end{tikzpicture}
caption{One-dimensional parameter space illustrating the interval $[-2, 3)$.}
label{fig:parameter-interval}
end{figure}

Output and how to read it

When compiled with pdfLaTeX, XeLaTeX, or LuaLaTeX, the code generates a standalone vector graphic directly in the output PDF. Reading the elements involves standard mathematical conventions:

  • Axis arrows: The bidirectional arrowheads denote an unbounded continuous real line spanning (−∞, +∞).
  • Tick spacing: Equidistant tick marks represent regular coordinate units. In empirical figures, these can be calibrated to standard deviations (σ), z-scores, or percentage points.
  • Solid marker (bullet): A solid filled circle at a coordinate denotes that the boundary value is included in the solution set (corresponding to ≤, ≥, or closed brackets).
  • Hollow marker (ring): An open circle with a white fill indicates strict exclusion (corresponding to <, >, or open parentheses).
  • Vector scalability: Because the graphic is compiled as native PDF drawing paths rather than rasterized pixels, it maintains infinite resolution at any magnification, meeting high-resolution printing requirements.

Troubleshooting

Review these solutions to resolve common TikZ compilation errors:

1. Undefined control sequence: begin{tikzpicture}

Cause: The compiler does not recognize the environment because the package was not loaded.
Fix: Ensure usepackage{tikz} appears in your document preamble before begin{document}.

2. Package PGF Math Error: Unknown operator or runaway argument

Cause: A missing terminating semicolon (;) at the end of a draw, node, or filldraw command.
Fix: Check that every TikZ path statement ends with a semicolon. Semicolons must also close statements nested inside foreach blocks.

3. TeX capacity exceeded or Dimension too large

Cause: Coordinate values exceed TeX’s arithmetic register limit (roughly 575 cm or 16,383 pt), often caused by using raw unscaled data values (e.g., coordinates from 0 to 1,000).
Fix: Apply a scale factor to the environment using [xscale=0.01] or normalize your data values to a 0–10 scale prior to plotting.

4. Diagram overflows text column or page margins

Cause: In two-column formats (such as IEEE or ACM conferences), a wide number line may exceed the column width (typically ~8.5 cm).
Fix: Scale the entire picture using [scale=0.75, every node/.transform shape] or wrap the environment in resizebox{columnwidth}{!}{...} from the graphicx package.

5. Label text renders without proper negative signs

Cause: Negative coordinates passed directly into text mode render with short hyphens rather than proper typographical minus signs.
Fix: Enclose the variable in math mode within the node text: {$x$} rather than plain {x}.

Free alternatives

While TikZ is the primary tool for direct in-document diagramming, researchers can choose between several free and open-source alternatives depending on project requirements:

Tool / Package Environment Best Research Use Case Syntax Complexity Output Format
TikZ (PGF) Native LaTeX Conceptual 1D axes, mathematical intervals, custom analytical diagrams Moderate (macro-based) Native PDF vector paths
pgfplots Native LaTeX Empirical scientific axes, calibrated coordinate graphs, statistical distributions Moderate to high Native PDF vector paths
tzplot / nl-interval Native LaTeX (CTAN) Rapid shorthand macros for teaching notes and elementary interval plotting Low Native PDF vector paths
Python (Matplotlib) Python / Jupyter Automated pipeline generation, simulation runs, large experimental datasets Moderate Vector PDF, SVG, or EPS
R (ggplot2) R / RStudio Biostatistical confidence intervals, forest plots, regression coefficient lines Moderate Vector PDF, SVG, or EPS

FAQ

What is the difference between numberline and drawing a number line in LaTeX?

The command numberline is a core LaTeX typesetting macro used exclusively inside table of contents entries to format section numbers. It does not produce graphical lines. Drawing a mathematical coordinate number line requires a vector graphics package such as TikZ or pgfplots.

How do I draw tick marks at non-integer or decimal intervals?

Specify the desired increment explicitly in the foreach loop by providing the first two values followed by an ellipsis: foreach x in {0, 0.5, ..., 5.0} { ... }. TikZ will automatically calculate subsequent ticks based on the 0.5 step size.

How do I represent inclusive versus exclusive endpoints on an interval?

Use filldraw[color] (x, y) circle (radius); to create a solid dot for inclusive endpoints (≤ or ≥). Use draw[color, thick, fill=white] (x, y) circle (radius); to create a hollow dot with a white interior for exclusive endpoints (< or >).

How do I add custom text labels to specific points on the axis?

Use the node command at the target coordinate. Specify placement relative to the point with options such as [above=4pt], [below=4pt], or [above right], for example: node[above=4pt] at (0, 0) {$mu = 0$};.

Can I customize arrowhead shapes on the number line?

Yes. Load usetikzlibrary{arrows.meta} in your preamble. You can then specify modern arrowhead styles such as [{Stealth}-{Stealth}] or [{Latex}-{Latex}] within the axis draw options: draw[{Stealth}-{Stealth}, thick] (-5, 0) -- (5, 0);.

Sources

  • Tantau, T., Feuersänger, C., et al. (2026). The TikZ and PGF Packages: Manual for version 3.1.10. Comprehensive TeX Archive Network (CTAN). URL: https://www.ctan.org/pkg/pgf. Checked: 2026-11-07.
  • Overleaf Documentation Team. (2026). TikZ package documentation and coordinate tutorial. Digital Science / Overleaf. URL: https://www.overleaf.com/learn/latex/TikZ_package. Checked: 2026-11-07.
  • LaTeX3 Project / Berry, K. (2026). LaTeX2e: An unofficial reference manual (numberline entry). URL: https://latexref.xyz/_005cnumberline.html. Checked: 2026-11-07.
  • Feuersänger, C. (2026). Manual for the pgfplots Package. Comprehensive TeX Archive Network (CTAN). URL: https://www.ctan.org/pkg/pgfplots. Checked: 2026-11-07.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Number Line in LaTeX: TikZ Syntax and Axis Setup

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →