> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Page Numbering in LaTeX - Roman, Arabic, and Custom Styles

> Learn how to add page numbers in LaTeX, switch between roman and arabic numbering, reset counters, and show Page X of Y with copy-paste examples.

export const RenderedOutput = ({title = "Rendered output", ctaHref, ctaLabel = "Open LaTeX Cloud Studio", children}) => {
  const [isExpanded, setIsExpanded] = useState(false);
  const trackEditorCta = () => {
    const target = new URL(ctaHref, window.location.href);
    globalThis.posthog?.capture?.("docs_app_cta_clicked", {
      source_page: window.location.pathname,
      source_section: "rendered_output",
      cta_variant: "first_compiled_example",
      target_url: target.toString(),
      target_utm_source: target.searchParams.get("utm_source"),
      target_utm_medium: target.searchParams.get("utm_medium"),
      target_utm_campaign: target.searchParams.get("utm_campaign"),
      target_utm_content: target.searchParams.get("utm_content")
    }, {
      transport: "sendBeacon",
      send_instantly: true
    });
  };
  return <details className="rendered-output" onToggle={event => setIsExpanded(event.currentTarget.open)}>
      <summary className="rendered-output__summary">
        <span className="rendered-output__title">{title}</span>
        <span className="rendered-output__hint" aria-hidden="true">View compiled result</span>
      </summary>
      {isExpanded && <div className="rendered-output__content">
          {children}
          {ctaHref && <aside className="rendered-output__cta" aria-label="Continue in the LaTeX editor">
              <span>
                <strong>Ready to use this syntax?</strong>
                Continue in the browser editor when you want to adapt the example in a real project.
              </span>
              <a href={ctaHref} onClick={trackEditorCta}>{ctaLabel}<span aria-hidden="true"> →</span></a>
            </aside>}
        </div>}
    </details>;
};

export const LatexSource = ({filename, source}) => {
  const [copyStatus, setCopyStatus] = useState("Copy");
  const copySource = async () => {
    try {
      await navigator.clipboard.writeText(source);
      setCopyStatus("Copied");
    } catch {
      setCopyStatus("Select and copy");
    }
  };
  return <figure className="latex-source">
      <figcaption className="latex-source__header">
        <span className="latex-source__filename">{filename}</span>
        <button type="button" className="latex-source__copy" onClick={copySource} aria-live="polite">
          {copyStatus}
        </button>
      </figcaption>
      <pre className="latex-source__pre" aria-label={`LaTeX source: ${filename}`} tabIndex="0">
        <code className="language-latex">{source}</code>
      </pre>
    </figure>;
};

export const LatexPreview = ({src, alt, caption, width, height}) => {
  const minZoom = 1;
  const maxZoom = 3;
  const zoomStep = 0.5;
  const measureSvgContent = async (assetSrc, pageWidth, pageHeight) => {
    const cacheKey = "__latexCloudSvgContentBoxCache";
    const contentBoxCache = globalThis[cacheKey] ?? new Map();
    globalThis[cacheKey] = contentBoxCache;
    if (contentBoxCache.has(assetSrc)) return contentBoxCache.get(assetSrc);
    const measurement = (async () => {
      const assetUrl = new URL(assetSrc, window.location.href);
      if (assetUrl.origin !== window.location.origin) {
        throw new Error("Rendered output must use a same-origin SVG asset.");
      }
      const response = await fetch(assetUrl, {
        credentials: "same-origin"
      });
      if (!response.ok) throw new Error(`Rendered output request failed with ${response.status}.`);
      const source = await response.text();
      const documentNode = new DOMParser().parseFromString(source, "image/svg+xml");
      if (documentNode.querySelector("parsererror")) throw new Error("Rendered output is not valid SVG.");
      const sourceSvg = documentNode.documentElement;
      sourceSvg.querySelectorAll("script, foreignObject").forEach(node => node.remove());
      [sourceSvg, ...sourceSvg.querySelectorAll("*")].forEach(node => {
        [...node.attributes].forEach(attribute => {
          if ((/^on/i).test(attribute.name)) node.removeAttribute(attribute.name);
          if ((attribute.name === "href" || attribute.name === "xlink:href") && !attribute.value.startsWith("#")) {
            node.removeAttribute(attribute.name);
          }
        });
      });
      const measurementHost = document.createElement("div");
      measurementHost.className = "latex-preview__measurement-host";
      const measuredSvg = document.importNode(sourceSvg, true);
      measuredSvg.setAttribute("aria-hidden", "true");
      measurementHost.appendChild(measuredSvg);
      document.body.appendChild(measurementHost);
      try {
        const measuredElements = [...measuredSvg.children].filter(node => !["defs", "desc", "metadata", "style", "title"].includes(node.tagName.toLowerCase()));
        const elementBounds = measuredElements.map(node => node.getBBox()).filter(box => [box.x, box.y, box.width, box.height].every(Number.isFinite) && box.width > 0 && box.height > 0);
        if (elementBounds.length === 0) {
          throw new Error("Rendered output has no measurable visible content.");
        }
        const sortedBounds = [...elementBounds].sort((left, right) => left.y - right.y);
        const clusterGap = pageHeight * 0.045;
        const clusters = [];
        sortedBounds.forEach(box => {
          const current = clusters[clusters.length - 1];
          if (!current || box.y - current.bottom > clusterGap) {
            clusters.push({
              boxes: [box],
              bottom: box.y + box.height
            });
            return;
          }
          current.boxes.push(box);
          current.bottom = Math.max(current.bottom, box.y + box.height);
        });
        const contentClusters = clusters.filter(cluster => {
          const clusterBox = cluster.boxes.reduce((combined, box) => {
            const right = Math.max(combined.x + combined.width, box.x + box.width);
            const bottom = Math.max(combined.y + combined.height, box.y + box.height);
            const x = Math.min(combined.x, box.x);
            const y = Math.min(combined.y, box.y);
            return {
              x,
              y,
              width: right - x,
              height: bottom - y
            };
          });
          const centerY = clusterBox.y + clusterBox.height / 2;
          const isMarginFurniture = cluster.boxes.length <= 2 && clusterBox.width < pageWidth * 0.2 && clusterBox.height < pageHeight * 0.04 && (centerY < pageHeight * 0.08 || centerY > pageHeight * 0.8);
          return !isMarginFurniture;
        });
        const visibleBounds = (contentClusters.length > 0 ? contentClusters : clusters).flatMap(cluster => cluster.boxes);
        const bounds = visibleBounds.reduce((combined, box) => {
          const right = Math.max(combined.x + combined.width, box.x + box.width);
          const bottom = Math.max(combined.y + combined.height, box.y + box.height);
          const x = Math.min(combined.x, box.x);
          const y = Math.min(combined.y, box.y);
          return {
            x,
            y,
            width: right - x,
            height: bottom - y
          };
        });
        const clampValue = (value, minimum, maximum) => Math.min(maximum, Math.max(minimum, value));
        const padding = Math.max(8, Math.min(pageWidth, pageHeight) * 0.025);
        const x = clampValue(bounds.x - padding, 0, pageWidth);
        const y = clampValue(bounds.y - padding, 0, pageHeight);
        const right = clampValue(bounds.x + bounds.width + padding, 0, pageWidth);
        const bottom = clampValue(bounds.y + bounds.height + padding, 0, pageHeight);
        return {
          x,
          y,
          width: right - x,
          height: bottom - y
        };
      } finally {
        measurementHost.remove();
      }
    })();
    contentBoxCache.set(assetSrc, measurement);
    measurement.catch(() => contentBoxCache.delete(assetSrc));
    return measurement;
  };
  const renderPreviewAsset = ({contentBox: assetContentBox, loading}) => {
    if (!assetContentBox) {
      return <img className="latex-preview__asset" src={src} alt={alt} width={width} height={height} loading={loading} draggable="false" />;
    }
    return <svg className="latex-preview__asset" viewBox={`${assetContentBox.x} ${assetContentBox.y} ${assetContentBox.width} ${assetContentBox.height}`} preserveAspectRatio="xMidYMid meet" role="img" aria-label={alt}>
        <image href={src} x="0" y="0" width={width} height={height} />
      </svg>;
  };
  const [isOpen, setIsOpen] = useState(false);
  const [frameMode, setFrameMode] = useState("content");
  const [viewMode, setViewMode] = useState("fit");
  const [zoom, setZoom] = useState(minZoom);
  const [contentBox, setContentBox] = useState(null);
  const [measurementStatus, setMeasurementStatus] = useState("loading");
  const dialogRef = useRef(null);
  const closeButtonRef = useRef(null);
  const viewportRef = useRef(null);
  const previousFocusRef = useRef(null);
  const dragRef = useRef(null);
  useEffect(() => {
    let isCurrent = true;
    setMeasurementStatus("loading");
    measureSvgContent(src, width, height).then(box => {
      if (!isCurrent) return;
      setContentBox(box);
      setMeasurementStatus("ready");
    }).catch(() => {
      if (!isCurrent) return;
      setContentBox(null);
      setFrameMode("page");
      setMeasurementStatus("error");
    });
    return () => {
      isCurrent = false;
    };
  }, [height, src, width]);
  const closeViewer = useCallback(() => {
    setIsOpen(false);
  }, []);
  const openViewer = () => {
    previousFocusRef.current = document.activeElement;
    setFrameMode(contentBox ? "content" : "page");
    setViewMode("fit");
    setZoom(minZoom);
    setIsOpen(true);
  };
  const applyZoom = useCallback(nextZoom => {
    const boundedZoom = Math.min(maxZoom, Math.max(minZoom, nextZoom));
    setViewMode("custom");
    setZoom(boundedZoom);
  }, []);
  const zoomIn = useCallback(() => {
    applyZoom(viewMode === "fit" ? minZoom + zoomStep : zoom + zoomStep);
  }, [applyZoom, viewMode, zoom]);
  const zoomOut = useCallback(() => {
    applyZoom(viewMode === "fit" ? minZoom : zoom - zoomStep);
  }, [applyZoom, viewMode, zoom]);
  useEffect(() => {
    if (!isOpen) return undefined;
    const previousOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    closeButtonRef.current?.focus();
    return () => {
      document.body.style.overflow = previousOverflow;
      previousFocusRef.current?.focus?.();
    };
  }, [isOpen]);
  useEffect(() => {
    if (!isOpen) return undefined;
    const handleKeyDown = event => {
      if (event.key === "Escape") {
        event.preventDefault();
        closeViewer();
        return;
      }
      if ((event.key === "+" || event.key === "=") && !event.metaKey && !event.ctrlKey) {
        event.preventDefault();
        zoomIn();
        return;
      }
      if (event.key === "-" && !event.metaKey && !event.ctrlKey) {
        event.preventDefault();
        zoomOut();
        return;
      }
      if (event.key !== "Tab" || !dialogRef.current) return;
      const focusable = [...dialogRef.current.querySelectorAll('button:not([disabled]), a[href], [tabindex]:not([tabindex="-1"])')];
      if (focusable.length === 0) return;
      const first = focusable[0];
      const last = focusable[focusable.length - 1];
      if (event.shiftKey && document.activeElement === first) {
        event.preventDefault();
        last.focus();
      } else if (!event.shiftKey && document.activeElement === last) {
        event.preventDefault();
        first.focus();
      }
    };
    window.addEventListener("keydown", handleKeyDown);
    return () => {
      window.removeEventListener("keydown", handleKeyDown);
    };
  }, [closeViewer, isOpen, zoomIn, zoomOut]);
  const startDrag = event => {
    if (event.button !== 0 || !viewportRef.current) return;
    const viewport = viewportRef.current;
    dragRef.current = {
      pointerId: event.pointerId,
      x: event.clientX,
      y: event.clientY,
      scrollLeft: viewport.scrollLeft,
      scrollTop: viewport.scrollTop
    };
    viewport.setPointerCapture(event.pointerId);
    viewport.dataset.dragging = "true";
  };
  const continueDrag = event => {
    const drag = dragRef.current;
    const viewport = viewportRef.current;
    if (!drag || !viewport || drag.pointerId !== event.pointerId) return;
    viewport.scrollLeft = drag.scrollLeft - (event.clientX - drag.x);
    viewport.scrollTop = drag.scrollTop - (event.clientY - drag.y);
  };
  const stopDrag = event => {
    const viewport = viewportRef.current;
    if (viewport?.hasPointerCapture(event.pointerId)) viewport.releasePointerCapture(event.pointerId);
    if (viewport) delete viewport.dataset.dragging;
    dragRef.current = null;
  };
  const activeContentBox = frameMode === "content" ? contentBox : null;
  const activeWidth = activeContentBox?.width ?? width;
  const activeHeight = activeContentBox?.height ?? height;
  const activeRatio = activeWidth / activeHeight;
  const inlineContentBox = measurementStatus === "ready" ? contentBox : null;
  const inlineWidth = inlineContentBox?.width ?? width;
  const inlineHeight = inlineContentBox?.height ?? height;
  const inlineGeometry = {
    aspectRatio: `${inlineWidth} / ${inlineHeight}`,
    maxWidth: `${30 * inlineWidth / inlineHeight}rem`
  };
  const imageStyle = viewMode === "fit" ? {
    aspectRatio: `${activeWidth} / ${activeHeight}`,
    width: "100%",
    maxWidth: `${Math.max(16, activeRatio * 78)}dvh`
  } : {
    aspectRatio: `${activeWidth} / ${activeHeight}`,
    width: `${zoom * 100}%`,
    maxWidth: "none"
  };
  const zoomLabel = viewMode === "fit" ? frameMode === "content" ? "Fit content" : "Full page" : `${Math.round(zoom * 100)}%`;
  return <figure className="latex-preview">
      <button type="button" className="latex-preview__trigger" onClick={openViewer} aria-haspopup="dialog" aria-label={`Open zoomable preview: ${alt}`}>
        <span className="latex-preview__page" style={inlineGeometry}>
          {measurementStatus === "loading" ? <span className="latex-preview__loading" role="status">Preparing compiled output…</span> : renderPreviewAsset({
    src,
    alt,
    width,
    height,
    contentBox: inlineContentBox,
    loading: "lazy"
  })}
        </span>
        <span className="latex-preview__trigger-label" aria-hidden="true">
          <span className="latex-preview__trigger-icon">⌕</span>
          Open viewer
        </span>
      </button>
      <figcaption className="latex-preview__caption">
        <span>
          {caption}
          {measurementStatus === "error" && <span className="latex-preview__status" role="status"> Content fit is unavailable; the complete vector page is shown.</span>}
        </span>
        <a href={src} target="_blank" rel="noreferrer" className="latex-preview__source-link">Open SVG</a>
      </figcaption>

      {isOpen && <div className="latex-preview__backdrop" onMouseDown={event => {
    if (event.target === event.currentTarget) closeViewer();
  }}>
          <section ref={dialogRef} className="latex-preview__dialog" role="dialog" aria-modal="true" aria-label={`Rendered LaTeX viewer: ${alt}`}>
            <header className="latex-preview__toolbar">
              <div className="latex-preview__identity">
                <span className="latex-preview__eyebrow">Compiled LaTeX</span>
                <span className="latex-preview__filename">{alt}</span>
              </div>
              <div className="latex-preview__controls" aria-label="Preview controls">
                <button type="button" className={frameMode === "content" && viewMode === "fit" ? "is-active" : undefined} disabled={!contentBox} onClick={() => {
    setFrameMode("content");
    setViewMode("fit");
    setZoom(minZoom);
  }}>
                  Fit content
                </button>
                <button type="button" className={frameMode === "page" && viewMode === "fit" ? "is-active" : undefined} onClick={() => {
    setFrameMode("page");
    setViewMode("fit");
    setZoom(minZoom);
  }}>
                  Full page
                </button>
                <span className="latex-preview__zoom-group">
                  <button type="button" onClick={zoomOut} disabled={viewMode === "fit" || zoom <= minZoom} aria-label="Zoom out">−</button>
                  <output aria-live="polite" aria-label="Current zoom">{zoomLabel}</output>
                  <button type="button" onClick={zoomIn} disabled={viewMode !== "fit" && zoom >= maxZoom} aria-label="Zoom in">+</button>
                </span>
                <a href={src} target="_blank" rel="noreferrer">Open SVG</a>
                <button ref={closeButtonRef} type="button" className="latex-preview__close" onClick={closeViewer} aria-label="Close rendered LaTeX viewer">
                  Close
                </button>
              </div>
            </header>
            <div ref={viewportRef} className="latex-preview__viewport" data-view-mode={viewMode} onPointerDown={startDrag} onPointerMove={continueDrag} onPointerUp={stopDrag} onPointerCancel={stopDrag}>
              <span className="latex-preview__dialog-page" style={imageStyle}>
                {renderPreviewAsset({
    src,
    alt,
    width,
    height,
    contentBox: activeContentBox
  })}
              </span>
            </div>
            <footer className="latex-preview__viewer-note">
              Compiler-generated vector output · Use +/− to zoom · Drag to pan · Esc to close
            </footer>
          </section>
        </div>}
    </figure>;
};

LaTeX adds page numbers automatically, but you can change the numbering style, restart the counter, hide numbers on selected pages, or show `Page X of Y` when you need a more formal layout.

<Info>
  **Quick answer**:

  <LatexSource filename="example.tex" source={"\\pagenumbering{roman}   % i, ii, iii\n\\pagenumbering{arabic}  % 1, 2, 3\n\\setcounter{page}{1}    % restart from page 1"} />

  <RenderedOutput title="Expected effect">
    <Info>
      This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
    </Info>
  </RenderedOutput>

  Use `\pagenumbering{...}` to change style and `\setcounter{page}{...}` to restart numbering.

  **Most common jobs**: switch front matter to roman numerals, restart page 1 for the main document, hide numbers on title pages, and show `Page X of Y` with `fancyhdr` and `lastpage`.

  **Related topics**: [Headers and footers](/learn/latex/formatting/headers-footers) | [Document classes](/learn/reference/document-classes) | [Cross-referencing](/learn/latex/cross-referencing)
</Info>

## Common Page Numbering Tasks

Most page-numbering questions fall into one of these patterns:

* Start with arabic page numbers like `1, 2, 3`
* Use roman numerals like `i, ii, iii` for front matter
* Restart numbering after the title page or table of contents
* Hide the page number on one page with `\thispagestyle{empty}`
* Show `Page X of Y` in the footer
* Move the number into a custom header or footer with `fancyhdr`

## Basic Page Numbering

### Default Numbering

LaTeX automatically numbers pages starting from 1. The page number appears in different locations depending on the document class and page style.

<LatexSource filename="basic-numbering.tex" source={"\\documentclass{article}\n\\begin{document}\n\n% Page numbers appear automatically\n\\section{Introduction}\nThis is page 1.\n\n\\newpage\n\\section{Methods}\nThis is page 2.\n\n\\newpage\n\\section{Results}\nThis is page 3.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output" ctaHref="https://app.latex-cloud-studio.com/?utm_source=resources&utm_medium=rendered_output&utm_campaign=docs_open_app&utm_content=learn_latex_formatting_page_numbering">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-02/page-1.svg" alt="Compiled PDF page 1 from basic-numbering.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-02/page-2.svg" alt="Compiled PDF page 2 from basic-numbering.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-02/page-3.svg" alt="Compiled PDF page 3 from basic-numbering.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Changing Page Number Style

<LatexSource filename="number-styles.tex" source={"\\documentclass{article}\n\\begin{document}\n\n% Arabic numerals (default)\n\\pagenumbering{arabic}\nPage numbering: 1, 2, 3, 4...\n\n\\newpage\n% Roman numerals (lowercase)\n\\pagenumbering{roman}\nPage numbering: i, ii, iii, iv...\n\n\\newpage\n% Roman numerals (uppercase)\n\\pagenumbering{Roman}\nPage numbering: I, II, III, IV...\n\n\\newpage\n% Alphabetic (lowercase)\n\\pagenumbering{alph}\nPage numbering: a, b, c, d...\n\n\\newpage\n% Alphabetic (uppercase)\n\\pagenumbering{Alph}\nPage numbering: A, B, C, D...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-03/page-1.svg" alt="Compiled PDF page 1 from number-styles.tex" caption="Page 1 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-03/page-2.svg" alt="Compiled PDF page 2 from number-styles.tex" caption="Page 2 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-03/page-3.svg" alt="Compiled PDF page 3 from number-styles.tex" caption="Page 3 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-03/page-4.svg" alt="Compiled PDF page 4 from number-styles.tex" caption="Page 4 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-03/page-5.svg" alt="Compiled PDF page 5 from number-styles.tex" caption="Page 5 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Setting Page Number

<LatexSource filename="set-page-number.tex" source={"\\documentclass{article}\n\\begin{document}\n\n% Start numbering from a specific number\n\\setcounter{page}{5}\nThis page is numbered 5.\n\n\\newpage\nThis page is numbered 6.\n\n% Reset counter\n\\setcounter{page}{1}\n\\newpage\nBack to page 1.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-04/page-1.svg" alt="Compiled PDF page 1 from set-page-number.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-04/page-2.svg" alt="Compiled PDF page 2 from set-page-number.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-04/page-3.svg" alt="Compiled PDF page 3 from set-page-number.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Page Number Positioning

If you only want to move the page number, keep the numbering logic simple here and move to [Headers and footers](/learn/latex/formatting/headers-footers) when you need a custom header/footer layout.

### Using Page Styles

<LatexSource filename="page-styles.tex" source={"\\documentclass{article}\n\\begin{document}\n\n% Plain style: number at bottom center\n\\pagestyle{plain}\n\\section{Section with Plain Style}\nPage number appears at bottom center.\n\n\\newpage\n% Empty style: no page numbers\n\\pagestyle{empty}\n\\section{Section with No Numbers}\nThis page has no page number.\n\n\\newpage\n% Headings style: number in header\n\\pagestyle{headings}\n\\section{Section with Header Numbers}\nPage number appears in header with section name.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-05/page-1.svg" alt="Compiled PDF page 1 from page-styles.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-05/page-2.svg" alt="Compiled PDF page 2 from page-styles.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-05/page-3.svg" alt="Compiled PDF page 3 from page-styles.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Custom Positioning with fancyhdr

<LatexSource filename="custom-positioning.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\n% Set up custom page numbering\n\\pagestyle{fancy}\n\\fancyhf{} % Clear all headers and footers\n\n% Page number in different positions\n\\fancyfoot[L]{Page \\thepage}     % Bottom left\n% \\fancyfoot[C]{\\thepage}        % Bottom center\n% \\fancyfoot[R]{\\thepage}        % Bottom right\n% \\fancyhead[L]{\\thepage}        % Top left\n% \\fancyhead[C]{\\thepage}        % Top center\n% \\fancyhead[R]{\\thepage}        % Top right\n\n\\begin{document}\n\n\\section{Custom Page Positioning}\nPage numbers can appear anywhere you specify.\n\n\\newpage\n\\section{Continued Content}\nConsistent positioning across pages.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-06/page-1.svg" alt="Compiled PDF page 1 from custom-positioning.tex" caption="Page 1 of 2. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-06/page-2.svg" alt="Compiled PDF page 2 from custom-positioning.tex" caption="Page 2 of 2. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Advanced Page Numbering

### Different Styles for Different Sections

<LatexSource filename="different-styles.tex" source={"\\documentclass{report}\n\\usepackage{fancyhdr}\n\n\\begin{document}\n\n% Front matter with roman numerals\n\\pagenumbering{roman}\n\\pagestyle{plain}\n\n\\tableofcontents\n\\newpage\n\n\\listoffigures\n\\newpage\n\n% Main content with arabic numerals\n\\pagenumbering{arabic}\n\\setcounter{page}{1}\n\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyhead[R]{\\thepage}\n\\fancyfoot[C]{Main Document}\n\n\\chapter{Introduction}\nMain content starts with page 1.\n\n\\chapter{Methods}\nContinues with normal numbering.\n\n% Appendix with different style\n\\appendix\n\\pagenumbering{Alph}\n\\setcounter{page}{1}\n\n\\chapter{Additional Data}\nAppendix uses alphabetic numbering: A, B, C...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-07/page-1.svg" alt="Compiled PDF page 1 from different-styles.tex" caption="Page 1 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-07/page-2.svg" alt="Compiled PDF page 2 from different-styles.tex" caption="Page 2 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-07/page-3.svg" alt="Compiled PDF page 3 from different-styles.tex" caption="Page 3 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-07/page-4.svg" alt="Compiled PDF page 4 from different-styles.tex" caption="Page 4 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-07/page-5.svg" alt="Compiled PDF page 5 from different-styles.tex" caption="Page 5 of 5. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Page Ranges and Prefixes

<LatexSource filename="page-ranges.tex" source={"\\documentclass{book}\n\\usepackage{fancyhdr}\n\n\\begin{document}\n\n% Preface with prefix\n\\pagenumbering{roman}\n\\renewcommand{\\thepage}{Preface-\\roman{page}}\n\n\\chapter*{Preface}\nPages numbered as: Preface-i, Preface-ii, etc.\n\n\\tableofcontents\n\n% Main content\n\\mainmatter\n\\pagenumbering{arabic}\n\\renewcommand{\\thepage}{\\arabic{page}}\n\n\\chapter{Introduction}\nRegular numbering: 1, 2, 3...\n\n% Appendix with prefix\n\\appendix\n\\renewcommand{\\thepage}{App-\\Alph{chapter}-\\arabic{page}}\n\\setcounter{page}{1}\n\n\\chapter{Data Tables}\nNumbered as: App-A-1, App-A-2, etc.\n\n\\chapter{Code Listings}\nNumbered as: App-B-1, App-B-2, etc.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-1.svg" alt="Compiled PDF page 1 from page-ranges.tex" caption="Page 1 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-2.svg" alt="Compiled PDF page 2 from page-ranges.tex" caption="Page 2 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-3.svg" alt="Compiled PDF page 3 from page-ranges.tex" caption="Page 3 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-4.svg" alt="Compiled PDF page 4 from page-ranges.tex" caption="Page 4 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-5.svg" alt="Compiled PDF page 5 from page-ranges.tex" caption="Page 5 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-6.svg" alt="Compiled PDF page 6 from page-ranges.tex" caption="Page 6 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-7.svg" alt="Compiled PDF page 7 from page-ranges.tex" caption="Page 7 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-8.svg" alt="Compiled PDF page 8 from page-ranges.tex" caption="Page 8 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-08/page-9.svg" alt="Compiled PDF page 9 from page-ranges.tex" caption="Page 9 of 9. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Two-Sided Documents

### Different Numbering for Odd/Even Pages

<LatexSource filename="two-sided-numbering.tex" source={"\\documentclass[twoside]{article}\n\\usepackage{fancyhdr}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Different positions for odd and even pages\n\\fancyfoot[LE]{\\thepage}  % Left on even pages\n\\fancyfoot[RO]{\\thepage}  % Right on odd pages\n\n% Alternative: outside corners\n% \\fancyhead[LE,RO]{\\thepage}\n\n% Content in headers\n\\fancyhead[LE]{\\leftmark}  % Section name on left of even pages\n\\fancyhead[RO]{\\rightmark} % Subsection name on right of odd pages\n\n\\begin{document}\n\n\\section{First Section}\nContent that demonstrates two-sided numbering.\n\n\\newpage\n\\subsection{Subsection}\nMore content to show header differences.\n\n\\newpage\n\\section{Second Section}\nEven more content.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-09/page-1.svg" alt="Compiled PDF page 1 from two-sided-numbering.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-09/page-2.svg" alt="Compiled PDF page 2 from two-sided-numbering.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-09/page-3.svg" alt="Compiled PDF page 3 from two-sided-numbering.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Blank Pages in Two-Sided Documents

<LatexSource filename="blank-pages.tex" source={"\\documentclass[twoside,openright]{book}\n\\usepackage{fancyhdr}\n\n% Define style for blank pages\n\\fancypagestyle{blank}{%\n  \\fancyhf{}\n  \\renewcommand{\\headrulewidth}{0pt}\n  \\renewcommand{\\footrulewidth}{0pt}\n}\n\n% Command to insert blank page\n\\newcommand{\\blankpage}{%\n  \\newpage\n  \\thispagestyle{blank}\n  \\mbox{}\n  \\newpage\n}\n\n\\begin{document}\n\n\\chapter{First Chapter}\nContent here...\n\n% Insert blank page before new chapter\n\\blankpage\n\n\\chapter{Second Chapter}\nNew chapter content...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-10/page-1.svg" alt="Compiled PDF page 1 from blank-pages.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-10/page-2.svg" alt="Compiled PDF page 2 from blank-pages.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-10/page-3.svg" alt="Compiled PDF page 3 from blank-pages.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Special Page Numbering Schemes

### Chapter-Based Numbering

<LatexSource filename="chapter-numbering.tex" source={"\\documentclass{book}\n\n% Redefine page numbering to include chapter\n\\renewcommand{\\thepage}{\\thechapter-\\arabic{page}}\n\n% Reset page counter at each chapter\n\\usepackage{chngcntr}\n\\counterwithin{page}{chapter}\n\n\\begin{document}\n\n\\chapter{Introduction}\nPages numbered: 1-1, 1-2, 1-3...\n\n\\chapter{Methods}\nPages numbered: 2-1, 2-2, 2-3...\n\n\\chapter{Results}\nPages numbered: 3-1, 3-2, 3-3...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-11/page-1.svg" alt="Compiled PDF page 1 from chapter-numbering.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-11/page-2.svg" alt="Compiled PDF page 2 from chapter-numbering.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-11/page-3.svg" alt="Compiled PDF page 3 from chapter-numbering.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Section-Based Numbering

<LatexSource filename="section-numbering.tex" source={"\\documentclass{article}\n\n% Include section number in page numbering\n\\renewcommand{\\thepage}{\\thesection.\\arabic{page}}\n\n% Reset page counter for each section\n\\usepackage{chngcntr}\n\\counterwithin{page}{section}\n\n\\begin{document}\n\n\\section{Introduction}\nPages: 1.1, 1.2, 1.3...\n\n\\section{Literature Review}\nPages: 2.1, 2.2, 2.3...\n\n\\section{Methodology}\nPages: 3.1, 3.2, 3.3...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-12/page-1.svg" alt="Compiled PDF page 1 from section-numbering.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

### Total Page Count

<LatexSource filename="total-pages.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\\usepackage{lastpage}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Show current page of total pages\n\\fancyfoot[C]{Page \\thepage\\ of \\pageref{LastPage}}\n\n% Alternative with different formatting\n% \\fancyfoot[C]{\\thepage\\ / \\pageref{LastPage}}\n% \\fancyfoot[C]{[\\thepage\\ | \\pageref{LastPage}]}\n\n\\begin{document}\n\n\\section{Introduction}\nThis shows page X of Y format.\n\n\\newpage\n\\section{Content}\nMore content to demonstrate numbering.\n\n\\newpage\n\\section{Conclusion}\nFinal page shows total count.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-13/page-1.svg" alt="Compiled PDF page 1 from total-pages.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-13/page-2.svg" alt="Compiled PDF page 2 from total-pages.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-13/page-3.svg" alt="Compiled PDF page 3 from total-pages.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Conditional Page Numbering

### Hide Numbers on Specific Pages

<LatexSource filename="conditional-numbering.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\\usepackage{ifthen}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Conditional page numbering\n\\fancyfoot[C]{%\n  \\ifthenelse{\\value{page}=1}\n    {} % No number on first page\n    {\\thepage} % Number on other pages\n}\n\n% Alternative: hide on chapter pages\n\\fancyfoot[C]{%\n  \\ifthenelse{\\boolean{@mainmatter}}\n    {\\thepage}\n    {} % No numbers in front matter\n}\n\n\\begin{document}\n\n\\title{Document Title}\n\\maketitle\n\n\\newpage\n\\section{Introduction}\nThis page has a number.\n\n\\newpage\n\\section{Methods}\nThis page also has a number.\n\n\\end{document}"} />

<RenderedOutput title="Expected effect">
  <Info>
    This code is a contextual or intentionally partial LaTeX excerpt, not a self-contained compilable document. Its visible result depends on the surrounding document, so the documentation shows the expected role without inventing a standalone preview.
  </Info>
</RenderedOutput>

### Different Formats by Page Range

<LatexSource filename="format-by-range.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Different formatting based on page number\n\\fancyfoot[C]{%\n  \\ifnum\\value{page}<10\n    Page 0\\thepage  % Zero-padded for pages 1-9\n  \\else\n    Page \\thepage   % Normal for pages 10+\n  \\fi\n}\n\n% Alternative: different styles by range\n\\fancyhead[C]{%\n  \\ifnum\\value{page}<5\n    \\textit{Introduction Section}\n  \\else\n    \\ifnum\\value{page}<10\n      \\textit{Main Content}\n    \\else\n      \\textit{Appendices}\n    \\fi\n  \\fi\n}\n\n\\begin{document}\n\n\\section{Introduction}\nPages 1-4 show \"Introduction Section\"\n\n\\newpage \\newpage \\newpage \\newpage\n\n\\section{Main Content}\nPages 5-9 show \"Main Content\"\n\n\\newpage \\newpage \\newpage \\newpage \\newpage\n\n\\section{Appendices}\nPages 10+ show \"Appendices\"\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-15/page-1.svg" alt="Compiled PDF page 1 from format-by-range.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-15/page-2.svg" alt="Compiled PDF page 2 from format-by-range.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-15/page-3.svg" alt="Compiled PDF page 3 from format-by-range.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Multi-Volume Documents

### Volume and Page Numbering

<LatexSource filename="multi-volume.tex" source={"\\documentclass{book}\n\n% Define volume number\n\\newcounter{volume}\n\\setcounter{volume}{1}\n\n% Include volume in page numbering\n\\renewcommand{\\thepage}{Vol.\\Roman{volume}-\\arabic{page}}\n\n% Alternative format\n% \\renewcommand{\\thepage}{\\Roman{volume}:\\arabic{page}}\n\n\\begin{document}\n\n\\frontmatter\n% Front matter pages: Vol.I-i, Vol.I-ii, etc.\n\n\\mainmatter\n% Main content: Vol.I-1, Vol.I-2, etc.\n\n\\chapter{First Chapter}\nContent for volume 1...\n\n% Start new volume (in practice, this would be a new document)\n\\setcounter{volume}{2}\n\\setcounter{page}{1}\n\n\\chapter{Volume Two Content}\nPages now numbered: Vol.II-1, Vol.II-2, etc.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-16/page-1.svg" alt="Compiled PDF page 1 from multi-volume.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-16/page-2.svg" alt="Compiled PDF page 2 from multi-volume.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-16/page-3.svg" alt="Compiled PDF page 3 from multi-volume.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Customizing Number Appearance

### Styling Page Numbers

<LatexSource filename="styling-numbers.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\\usepackage{xcolor}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Styled page numbers\n\\fancyfoot[C]{%\n  \\textcolor{blue}{\\textbf{-- \\thepage\\ --}}\n}\n\n% Alternative styles\n% \\fancyfoot[C]{\\fbox{\\thepage}}  % Boxed\n% \\fancyfoot[C]{\\textsc{Page \\thepage}}  % Small caps\n% \\fancyfoot[C]{\\Large\\thepage}  % Large font\n\n% Decorative numbering\n\\fancyhead[C]{%\n  $\\cdot$ \\thepage\\ $\\cdot$\n}\n\n\\begin{document}\n\n\\section{Styled Numbers}\nDemonstrates various page number styling options.\n\n\\newpage\n\\section{More Content}\nConsistent styling across pages.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-17/page-1.svg" alt="Compiled PDF page 1 from styling-numbers.tex" caption="Page 1 of 2. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={612} height={792} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-17/page-2.svg" alt="Compiled PDF page 2 from styling-numbers.tex" caption="Page 2 of 2. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={612} height={792} />
</RenderedOutput>

### Custom Number Commands

<LatexSource filename="custom-commands.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\n% Custom page number formatting\n\\newcommand{\\fancypagenumber}{%\n  \\textbf{[Page \\thepage]}\n}\n\n\\newcommand{\\circledpagenumber}{%\n  \\textcircled{\\small\\thepage}\n}\n\n\\pagestyle{fancy}\n\\fancyhf{}\n\n% Use custom commands\n\\fancyfoot[C]{\\fancypagenumber}\n% Alternative: \\fancyfoot[C]{\\circledpagenumber}\n\n\\begin{document}\n\n\\section{Custom Formatting}\nPage numbers use custom styling commands.\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-18/page-1.svg" alt="Compiled PDF page 1 from custom-commands.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Troubleshooting Page Numbering

### Common Issues and Solutions

<LatexSource filename="troubleshooting.tex" source={"\\documentclass{article}\n\\usepackage{fancyhdr}\n\n\\begin{document}\n\n% Issue: Page numbers not showing\n% Solution: Make sure page style is set\n\\pagestyle{fancy}\n\\fancyhf{}\n\\fancyfoot[C]{\\thepage}\n\n% Issue: Numbers in wrong position\n% Solution: Clear and reset headers/footers\n\\fancyhf{}  % Clear everything first\n\\fancyfoot[C]{\\thepage}  % Then set what you want\n\n% Issue: Numbers not updating\n% Solution: Use \\thepage, not literal numbers\n\\fancyfoot[C]{\\thepage}  % Correct\n% \\fancyfoot[C]{1}       % Wrong - always shows 1\n\n% Issue: Numbering resets unexpectedly\n% Solution: Check for \\pagenumbering commands\n% Remove unwanted \\setcounter{page}{1} commands\n\nContent to demonstrate solutions...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-19/page-1.svg" alt="Compiled PDF page 1 from troubleshooting.tex" caption="Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Best Practices

<Tip>
  **Page numbering guidelines:**

  1. **Be consistent** - Use the same style throughout similar sections
  2. **Consider your audience** - Academic papers often use different schemes than business documents
  3. **Plan ahead** - Design your numbering scheme before starting
  4. **Test thoroughly** - Check numbering across all document sections
  5. **Use automation** - Let LaTeX handle numbering rather than manual placement
  6. **Follow conventions** - Front matter typically uses roman numerals, main content uses arabic
</Tip>

### Professional Examples

<LatexSource filename="professional-example.tex" source={"\\documentclass[twoside]{book}\n\\usepackage{fancyhdr}\n\n% Front matter style\n\\fancypagestyle{frontmatter}{%\n  \\fancyhf{}\n  \\fancyfoot[C]{\\roman{page}}\n  \\renewcommand{\\headrulewidth}{0pt}\n}\n\n% Main content style\n\\fancypagestyle{mainmatter}{%\n  \\fancyhf{}\n  \\fancyhead[LE,RO]{\\thepage}\n  \\fancyhead[LO]{\\leftmark}\n  \\fancyhead[RE]{\\rightmark}\n  \\renewcommand{\\headrulewidth}{0.4pt}\n}\n\n\\begin{document}\n\n% Front matter\n\\frontmatter\n\\pagestyle{frontmatter}\n\\tableofcontents\n\n% Main content\n\\mainmatter\n\\pagestyle{mainmatter}\n\n\\chapter{Introduction}\nProfessional numbering scheme...\n\n\\end{document}"} />

<RenderedOutput title="Rendered output">
  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-20/page-1.svg" alt="Compiled PDF page 1 from professional-example.tex" caption="Page 1 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-20/page-2.svg" alt="Compiled PDF page 2 from professional-example.tex" caption="Page 2 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />

  <LatexPreview src="/images/rendered/learn-latex-formatting-page-numbering-20/page-3.svg" alt="Compiled PDF page 3 from professional-example.tex" caption="Page 3 of 3. Generated from the shown source with pdfLaTeX in the pinned LaTeXCloud TeX Live 2026 environment." width={595.276} height={841.89} />
</RenderedOutput>

## Quick Reference

### Page Numbering Commands

| Command                 | Purpose               | Example                 |
| ----------------------- | --------------------- | ----------------------- |
| `\pagenumbering{style}` | Set numbering style   | `\pagenumbering{roman}` |
| `\setcounter{page}{n}`  | Set page number       | `\setcounter{page}{1}`  |
| `\thepage`              | Current page number   | Use in headers/footers  |
| `\pageref{label}`       | Reference page number | `\pageref{LastPage}`    |

### Numbering Styles

| Style    | Output            | Typical Use       |
| -------- | ----------------- | ----------------- |
| `arabic` | 1, 2, 3, 4...     | Main content      |
| `roman`  | i, ii, iii, iv... | Front matter      |
| `Roman`  | I, II, III, IV... | Volume numbers    |
| `alph`   | a, b, c, d...     | Appendix sections |
| `Alph`   | A, B, C, D...     | Appendix chapters |

### Position Codes (with fancyhdr)

| Code | Position | Code | Position     |
| ---- | -------- | ---- | ------------ |
| `L`  | Left     | `E`  | Even pages   |
| `C`  | Center   | `O`  | Odd pages    |
| `R`  | Right    | `LE` | Left on even |

***

<Info>
  **Next**: Learn about [Single-sided vs double-sided documents](/learn/latex/formatting/document-sides) for layout considerations, or explore [Headers and footers](/learn/latex/formatting/headers-footers) for complementary page design.
</Info>
