2

I was trying to fit a gantt chart on a slide in beamer. I don't want to keep changing the dimensions of resizebox if the size of the gantt changes. I was reading the adjustbox package and on page 11 the documentation seems to indicate that there are some macros which automatically expand to the larger or smaller of width or length. There are four, \smallestside, \largestside, \Smallestside, \Largestside, but there aren't any examples. I would have assumed that as a macro you just put the stuff inside it you want to scale. That did not work.

Has anyone used these? I searched the forum for each of the terms and got no results....I'm open to other ideas, but it's frustrating that these macros seem to do exactly what I want but I can't figure out how to use them!

Bottom line, whatever I do, I don't want to have to change it. I want the gantt to max fill the available white space, either width or length, without changing aspect.

Here's what the output looks like (with all my REAL formatting):

notresized

And, here's an MWE (which eliminates most of the extra formatting but is the correct size and still shows the issue).

  \documentclass[xcolor = {usenames,dvipsnames,table},beamer]{standalone}

\usepackage{adjustbox}      
\usepackage{pgfgantt}

\begin{document}

%--------------------------------------------------------
\begin{frame}   {Timeline}

\begin{ganttchart}
    [
    y unit chart = 0.7cm,
    expand chart=\textwidth,
    time slot format=isodate,
    y unit title=0.5cm,
    title height=0.8,
    bar height = 0.4,
    bar label font = \tiny,
    milestone label font = \tiny,
    milestone height = 0.4,
    ]
{2020-01-0}{2020-08-31}

\gantttitle{Project Timeline}{244} \\
\gantttitlecalendar*{2020-01-0}{2020-08-31}{month=shortname} \\

% Elements
\ganttbar           {Model Development}         {2020-01-01}    {2020-03-15}\\
\ganttbar           {Model Verification}        {2020-02-20}    {2020-03-31}\\
\ganttmilestone     {Test Model}                {2020-03-31}    \\
\ganttbar           {Data Integration}          {2020-03-20}    {2020-04-15}\\
\ganttbar           {Scada Integration}         {2020-04-10}    {2020-04-30}\\
\ganttmilestone     {Full-Scale Model}          {2020-04-30}    \\
\ganttbar           {DCC Integration}           {2020-05-01}    {2020-05-20}\\
\ganttbar           {DCC-Parallel Operations}   {2020-05-20}    {2020-06-03}\\  
\ganttmilestone     {DCC-Full Operations}       {2020-06-04}    \\
\ganttbar           {Strategic Applications}    {2020-06-01}    {2020-07-15}

\end{ganttchart}

\end{frame}     
%--------------------------------------------------------

\end{document} 

2 Answers 2

1

If I don't misunderstand you, the answer is easy, I just added the adjustbox with the max width and the max height and I changed the expand chart= to a defined length:

\documentclass[xcolor = {usenames,dvipsnames,table},beamer]{standalone}

\usepackage{adjustbox, graphicx}      
\usepackage{pgfgantt}

\begin{document}

%--------------------------------------------------------
\begin{frame}   {Timeline}

  \begin{adjustbox}{max width=\textwidth, max height=\textheight}
    \begin{ganttchart}
      [ y unit chart = 5mm, expand chart=15cm, time slot format=isodate, y
      unit title=.7cm, title height=0.8, bar height = 0.4, bar label font = \tiny,
      milestone label font = \tiny, milestone height = 0.4, ]
      {2020-01-00}{2020-08-31}

      \gantttitle{Project Timeline}{244} \\
      \gantttitlecalendar*{2020-01-0}{2020-08-31}{month=shortname} \\

      % Elements
      \ganttbar           {Model Development}         {2020-01-01}    {2020-03-15}\\
      \ganttbar           {Model Verification}        {2020-02-20}    {2020-03-31}\\
      \ganttmilestone     {Test Model}                {2020-03-31}    \\
      \ganttbar           {Data Integration}          {2020-03-20}    {2020-04-15}\\
      \ganttbar           {Scada Integration}         {2020-04-10}    {2020-04-30}\\
      \ganttmilestone     {Full-Scale Model}          {2020-04-30}    \\
      \ganttbar           {DCC Integration}           {2020-05-01}    {2020-05-20}\\
      \ganttbar           {DCC-Parallel Operations}   {2020-05-20}    {2020-06-03}\\
      \ganttmilestone     {DCC-Full Operations}       {2020-06-04}    \\
      \ganttbar {Strategic Applications} {2020-06-01} {2020-07-15}\\
      \ganttbar {Dummy1 and a terribly long text} {2020-07-10}  {2020-08-13}\\
      \ganttbar {Dummy2} {2020-07-11}  {2020-08-23}\\
      \ganttbar {Dummy3} {2020-07-12}  {2020-08-30}\\
      \ganttbar {Dummy4} {2020-07-10}  {2020-08-13}\\
      \ganttbar {Dummy5} {2020-07-11}  {2020-08-23}\\
      \ganttbar {Dummy6} {2020-07-12}  {2020-08-30}\\


    \end{ganttchart}
 \end{adjustbox}


\end{frame}     
%--------------------------------------------------------

\end{document} 

I added up to 6 lines and even if you expand the timeline until end of october, it still will fitt the frame. However, the bar label font will become too small.

5
  • I was looking for a more elegant solution that wouldn't involve coming up with a number like 15cm. Something that would expand the chart until either it hit the top limit or the bottom limit. I doubled the lines and even with expanded to 15 cm it still spills over the bottom.
    – Jennifer
    Commented Dec 18, 2019 at 17:33
  • That comment went too soon. I played around with the expand options and the max width/length options. Is the purpose of expanding to 15cm to make it something LARGER than text width so it then shrinks down to text width? I guess that just confuses me a little. I understand that one adjustment happens inside of the gantt chart and the other is outside of it, but the difference between those two expand settings is a little odd. All I want the the thing to do is fill max space vertically or horizontally...which seems to look best with either your answer, provided I limit the bars.
    – Jennifer
    Commented Dec 18, 2019 at 17:36
  • And I will caveat that a bit. I want it to fill the horizontal space AND the vertical space. I am beginning to think that such a feat must be done within Gantt in a ratio close enough to the one needed in beamer, and then tweaking with adjust box. :-(
    – Jennifer
    Commented Dec 18, 2019 at 17:40
  • And now that I think about it, I was trying to use adjustbox to compensate for something lacking in pgfgantt so, maybe that's why it doesn't work. I guess I wish pgfgantt had a way to automatically distribute elements vertically like it does horizontally....
    – Jennifer
    Commented Dec 18, 2019 at 17:58
  • And I'd still love to know how to use \smallestside and \largestside and when you would want to use them....
    – Jennifer
    Commented Dec 18, 2019 at 17:58
1

I think you're barking up the wrong tree here. pgfgantt's expand chart only provides a horizontal stretching and there's no vertical counterpart. Additionally, the use of \smallestside (say) seems inappropriate for this, since your aim is to set some combined, fixed width and height to be (say) \textwidth and \textheight, respectively. \smallestside returns either \width or \totalheight of the object in question, whichever is smallest. So, you can't use it to fix the width (say), since the result may be \totalheight. Similarly, you can't use it to fix the height (say), since the result may be \width. And, depending on the use-case, \width and \totalheight may have nothing to do with one another.

As a showcase of what \smallestside and friends do, here are their definitions:

\def\smallestside{\ifdim\width<\totalheight \width\else\totalheight\fi}%
\def\largestside{\ifdim\width>\totalheight \width\else\totalheight\fi}%
\def\Smallestside{\ifdim\Width<\Totalheight \Width\else\Totalheight\fi}%
\def\Largestside{\ifdim\Width>\Totalheight \Width\else\Totalheight\fi}%

Note that they are all macros that return (or expand to) a length. Here's an example:

\documentclass{article}

\usepackage{adjustbox,graphicx}

\begin{document}

\begin{adjustbox}{width=\smallestside}
  \includegraphics[width=\textwidth,height=50pt]{example-image}
\end{adjustbox}

\end{document}

The contents of the adjustbox environment contains an image that has a width of \textwidth and a height of 50pt. It's easy to establish that \textwidth will be far larger than 50pt (in fact, it's 345pt in the above example). Since the image is the only thing contained within the adjustbox, its contents will have a \width of \textwidth and a \totalheight of 50pt. As such, \smallestside will result in 50pt, so that

\begin{adjustbox}{width=\smallestside}
  \includegraphics[width=\textwidth,height=50pt]{example-image}
\end{adjustbox}

will result in an image that has a width of 50pt - the smaller of \width (= \textwidth) and \totalheight (= 50pt) and a height of ~7.27pt (= 50pt x 50pt/\textwidth = 50pt x 50pt/345pt = 50pt x 0.145).

Similarly,

\begin{adjustbox}{height=\smallestside}
  \includegraphics[width=50pt,height=\textheight]{example-image}
\end{adjustbox}

would yield an image that has a height of 50pt - the smaller of \width (= 50pt) and \totalheight (= \textheight = 550pt) and a width of ~4.54pt (= 50pt x 50pt/\textheight = 50pt x 50pt/550pt = 50pt x 0.09).


Here is a possible use-case for \smallestside via conditionals (testing):

enter image description here

\documentclass{article}

\usepackage{adjustbox,graphicx}
\usepackage{showframe}% For reference

\begin{document}

\noindent % For reference
\includegraphics[width=.5\textwidth,height=50pt]{example-image}

\bigskip

\begin{adjustbox}{height={\ifdim\smallestside=\height 100pt\else\height\fi}}
  \includegraphics[width=.5\textwidth,height=50pt]{example-image}
\end{adjustbox}

\end{document}

The first image is for reference, set at a width of half the \textwidth (width=.5\textwidth). Within the adjustbox, we can adjust the height by conditioning on whether the \smallestside matches the \height. In the example, if \height turns out to the smallest, we set it at 100pt (twice its original size of 50pt). This should stretch the image from .5\textwidth (horizontally, or, the width key-value) to \textwidth. And that's what the second image shows.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .