Md Abdus Samad
  • About
    • News
    • Contact
  • Publications
  • Top Global Scholarships
  • University Information
  • LaTeX
  • Miscellaneous
    • List of Publishers
    • Journal Templates
    • Verifying Journal Indexing
    • Reference, Image Quality, and Detexify
    • Author Services by Major Publishers
    • Document Conversion and Figure Tools
    • Manuscript Anonymization
    • Switching Elsevier LaTeX Templates
    • DOCX to LaTeX Convert
    • LaTeX Reference and Label Management
    • Latex Reference Converter
    • Sequential Section Labels
    • Open Access Journals having Discount Policy
    • Overleaf git sync issues
    • Latexdiff Configuration Guide
    • Open source tools
    • Windows shortcuts & commands
    • Mathpix PDF to Word

On this page

  • Document Comparison and Track Changes
    • Compare Two .tex Files with latexdiff
    • Hide Deleted Text and Highlight Additions
  • Table Design and Layout
    • Color Entire Table
    • Adjust Table Spacing
    • Multi-Column Table Syntax
    • Multi-Row Table Syntax
    • Resize Table to Fit Page Width
  • Algorithm Formatting
    • Algorithm Autoref Support
    • Sub-Step Numbering in Algorithms
    • Split Algorithm Across Pages
  • Hyperlink Styling
    • Custom Link Colors
  • Citations and Bibliography
    • Force Numbered Style
    • Use (1) Style Instead of [1]
    • Back to Square Brackets
    • Show Citation Keys for Debugging
  • Compilation and Debugging
    • Show Loaded Packages
    • Delete Aux Files (Bash)
    • Full Compile Sequence (with BibTeX)
  • Git Integration with Overleaf
    • Clone Overleaf Project
    • Push Local Changes to Overleaf
    • Pull Before Push to Avoid Conflict
    • Command Summary
  • Opening PDFs from Git Bash on Windows
    • Navigate to Directory
    • Open PDF in Default Viewer
    • Automate Compile and Open
  • Word Counting in LaTeX
  • Creating LaTeX Tables with Merged Headers
    • Optional Customizations
  • TabularX Column Spacing Issues
    • Why This Happens
    • Solutions
  • Creating Sequential Dummy Figures in LaTeX with TikZ
    • What this code does
  • Quick Reference Table

LaTeX Reference Guide

Essential Commands and Tips for Academic Writing

Author

Dr. Md Abdus Samad

Published

May 30, 2025

Document Comparison and Track Changes

Compare Two .tex Files with latexdiff

latexdiff --append-context2cmd="abstract" old.tex new.tex > diff.tex

Generates diff.tex with additions underlined in red.

Hide Deleted Text and Highlight Additions

\providecommand{\DIFdel}[1]{}
\providecommand{\DIFadd}[1]{{\color{red}\uline{#1}}}

Table Design and Layout

Color Entire Table

{\color{red}
\begin{tabular}{cc}
a & b \\
1 & 2 \\
\end{tabular}}

Adjust Table Spacing

\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}

Multi-Column Table Syntax

\multicolumn{2}{c}{Merged Cell}

Multi-Row Table Syntax

\usepackage{multirow}
\multirow{2}{*}{Merged Row}

Resize Table to Fit Page Width

\resizebox{\linewidth}{!}{%
\begin{tabular}...\end{tabular}}

Algorithm Formatting

Algorithm Autoref Support

\newcommand{\algorithmautorefname}{Algorithm}

Sub-Step Numbering in Algorithms

\usepackage{algorithm,algpseudocode}
\newcounter{algsubstate}
\renewcommand{\thealgsubstate}{\alph{algsubstate}}
\newenvironment{algsubstates}{
\setcounter{algsubstate}{0}
\renewcommand{\State}{
\stepcounter{algsubstate}
\Statex {\footnotesize\thealgsubstate:}\space}}{}

Split Algorithm Across Pages

\usepackage{algorithm, algcompatible}
\algstore{blockname}
...
\algrestore{blockname}

Hyperlink Styling

Custom Link Colors

\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=blue,
urlcolor=blue,
allcolors=blue}
\urlstyle{same}

Citations and Bibliography

Force Numbered Style

\setcitestyle{numbers}

Use (1) Style Instead of [1]

\usepackage[numbers,round]{natbib}
\bibliographystyle{vancouver}

Back to Square Brackets

\usepackage[sort,numbers]{natbib}
\setcitestyle{square}

Show Citation Keys for Debugging

\usepackage{showlabels}
\renewcommand{\showlabelfont}{\small\color{blue}}
\showlabels[\small\color{gray}]{cite}
\showlabels[\small\color{red}]{bibitem}

Compilation and Debugging

Show Loaded Packages

\listfiles

Delete Aux Files (Bash)

rm -f *.aux *.log *.toc *.out *.lof *.lot *.fls *.fdb_latexmk *.synctex.gz *.nav *.snm *.bbl *.blg *.vrb *.xdv

Full Compile Sequence (with BibTeX)

latexmk -pdf main.tex
# or manual:
pdflatex main.tex 
bibtex main
pdflatex main.tex
pdflatex main.tex

Git Integration with Overleaf

TipGetting Started

In Overleaf: Menu → Git → Enable Git

Clone Overleaf Project

Copy URL like: https://git.overleaf.com/project-id

cd ~/Documents
git clone https://git.overleaf.com/project-id
cd project-id

Push Local Changes to Overleaf

git add .
git commit -m "Update"
git push

Pull Before Push to Avoid Conflict

git pull --rebase

Command Summary

Command Description
git pull origin master Pull changes from Overleaf (remote: origin, branch: master)
git push origin master Push your local changes to Overleaf
git pull overleaf master Same as above, but only if your remote is named overleaf

Opening PDFs from Git Bash on Windows

Navigate to Directory

cd /c/Users/YourName/Documents/latex-project

Open PDF in Default Viewer

start "" "main.pdf"
# or
explorer.exe "main.pdf"

Automate Compile and Open

pdflatex main.tex && start "" "main.pdf"

Word Counting in LaTeX

Use texcount for accurate word count:

texcount yourfile.tex
texcount -sum yourfile.tex
texcount -inc yourfile.tex
texcount -1 yourfile.tex
texcount -brief yourfile.tex
texcount -inc -sum -total main.tex

Creating LaTeX Tables with Merged Headers

NoteRequirements
  • Columns 1 and 2: vertical merge (2 rows)
  • Columns 3–5: under “Group Header” merged in first row, subheaders in second row
  • Column 6: vertical merge (2 rows)

Optional Customizations

  • Use booktabs for horizontal lines
  • Use tabularx with \textwidth for dynamic width
  • Center-align all columns
  • Add sample data rows
  • Include \caption{} and \label{}
  • Add colored headers (requires xcolor)
  • Ensure compilation-ready for Overleaf/TeXstudio

TabularX Column Spacing Issues

WarningProblem

Reducing column spacing with \setlength{\tabcolsep}{4pt} may lead to inconsistent column widths.

Why This Happens

  • Automatic Column Stretching: tabularx distributes remaining width among X columns proportionally
  • Reduced Padding: Smaller \tabcolsep makes differences more noticeable
  • Multiple X Columns: Algorithm may leave fractional rounding errors
  • Complex Tables: Multirow/multicolumn cells exacerbate uneven widths

Solutions

1. Use Proportional X Columns

\begin{tabularx}{\textwidth}{|>{\hsize=0.5\hsize}X|>{\hsize=1\hsize}X|c|}

2. Consider tabular* for Precise Control

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|l|l|l|}

3. Use Fixed-Width Columns

p{width}
TipPro Tips
  • Combine reduced \tabcolsep with \arraystretch for balanced spacing
  • Always test with multiple rows and different content lengths
  • For highly complex tables, consider splitting into smaller subtables

Creating Sequential Dummy Figures in LaTeX with TikZ

Sometimes you need placeholder figures while drafting. Here is how to generate 20 numbered dummy figures automatically:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\section*{Sequential Dummy Figures with TikZ}

% Define a command to create a numbered dummy image
\newcommand{\numberedimage}[1]{%
  \begin{figure}[h!]
    \centering
    \begin{tikzpicture}
      \draw[fill=gray!30] (0,0) rectangle (4,3); % gray rectangle
      \node at (2,1.5) {\Huge Image #1};         % centered label
    \end{tikzpicture}
    \caption{Dummy figure #1}
  \end{figure}
}

% Generate 20 dummy figures
\numberedimage{1}
\numberedimage{2}
\numberedimage{3}
% ...continue to 20

\end{document}

What this code does

  • Defines a custom command \numberedimage{n}
  • Each dummy figure is a gray rectangle with “Image n” written inside
  • Figures are numbered 1 through 20, each with its own caption
NoteUse Cases
  • Testing figure layouts
  • Reserving space for future graphics
  • Creating mockups in academic papers

Quick Reference Table

Category Command Purpose
Comparison latexdiff old.tex new.tex > diff.tex Compare documents
Tables \multicolumn{2}{c}{Text} Merge columns
Tables \multirow{2}{*}{Text} Merge rows
Tables \resizebox{\linewidth}{!}{...} Fit table to page
Algorithm \algorithmautorefname Autoref support
Links \hypersetup{colorlinks=true} Color hyperlinks
Citations \setcitestyle{numbers} Numbered citations
Compile latexmk -pdf main.tex Full compilation
Git git pull --rebase Sync with Overleaf
Word Count texcount -inc -sum main.tex Count words
 

© 2025 Dr. Md Abdus Samad. All rights reserved.