3

I have two Gantt charts using the pgfgantt package, and their typesetting is influenced by the longest label length. How can I make them aligned horizontally so that the left edge of the charts are aligned?

UPDATE: here is a minimal non-working example:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{pgfgantt}

\begin{document}

\begin{landscape}
\vspace*{\fill}
\begin{ganttchart}[
    hgrid,
    vgrid,
    time slot format=isodate-yearmonth,
    time slot unit=month,
    x unit=3em
]{2025-11}{2026-10}
  \gantttitlecalendar{year, month=shortname} \\

  \ganttbar{xxxxxxxxxxxxxxxxxxxxxxx}{2025-11}{2026-06} \\
  \ganttbar{xxxxxxxxxxxxxxxxxxxxxxxxxx}{2026-07}{2026-07} \\
  \ganttbar{xxxxxxxxxxxxxxxxxxx}{2026-08}{2026-08} \\
  \ganttbar{xxxxxxxxxxxxxxxxxx}{2026-09}{2026-10} 

\end{ganttchart}

\vspace{3em}
\begin{ganttchart}[
    hgrid,
    vgrid,
    time slot format=isodate-yearmonth,
    time slot unit=month,
    x unit=3em
]{2026-11}{2027-10}
  \gantttitlecalendar{year, month=shortname} \\

  \ganttbar{xxxxxxxxxxxxx}{2026-11}{2027-10} 

\end{ganttchart}
\vspace*{\fill}
\end{landscape}

\end{document}

LaTeX output

2
  • 2
    I did not downvote, but could you please add a code example showing the issue? Currently, it is not at all clear what you have and what you want the output to look like ... Commented 13 hours ago
  • 1
    Thanks, @JasperHabicht for being constructive and telling what is missing. I added a complete non-working example and its output. Commented 13 hours ago

2 Answers 2

3

One option is to \usepackage{calc}, and then wrap any label in the second table in \makebox[\widthof{longest label from first table}][r]{actual label}. With yours, that ends up being:

\ganttbar{\makebox[\widthof{xxxxxxxxxxxxxxxxxxxxxxxxxx}][r]{xxxxxxxxxxxxx}}{2026-11}{2027-10}

complete code output

3

You could right-align the charts. As long as the labels are short enough to fit in the line, their length won't matter:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{pgfgantt}

\begin{document}

\begin{landscape}
\vspace*{\fill}
\raggedleft
\begin{ganttchart}[
    hgrid,
    vgrid,
    time slot format=isodate-yearmonth,
    time slot unit=month,
    x unit=3em
]{2025-11}{2026-10}
  \gantttitlecalendar{year, month=shortname} \\

  \ganttbar{xxxxxxxxxxxxxxxxxxxxxxx}{2025-11}{2026-06} \\
  \ganttbar{xxxxxxxxxxxxxxxxxxxxxxxxxx}{2026-07}{2026-07} \\
  \ganttbar{xxxxxxxxxxxxxxxxxxx}{2026-08}{2026-08} \\
  \ganttbar{xxxxxxxxxxxxxxxxxx}{2026-09}{2026-10} 

\end{ganttchart}

\vspace{3em}
\begin{ganttchart}[
    hgrid,
    vgrid,
    time slot format=isodate-yearmonth,
    time slot unit=month,
    x unit=3em
]{2026-11}{2027-10}
  \gantttitlecalendar{year, month=shortname} \\

  \ganttbar{xxxxxxxxxxxxx}{2026-11}{2027-10} 

\end{ganttchart}
\vspace*{\fill}
\end{landscape}

\end{document}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.