#StackBounty: #spacing #vertical-alignment #boxes #dimensions Spacing difference when using boxes

Bounty: 200

On the left (obtained from the MWE below), I do not use boxes for the title nor the body text and the title and the text appears to be in the correct spot.

However, when I attempt to use newsaveboxs (MWE with defUseBoxes{} uncommented) I obtain the results on the right.

enter image description here
enter image description here

Questions:

  • What are this additional skip’s being inserted and how do I get both to exhibit identical behavior?
  • In my actual use case I can tweak the addition of the struts to get correct behavior, but that also seems to need a conditional based on if the body text is more than one line. My understanding is that I should only need a strut at the end of the body text, but that does not seem to work here.

Notes:

  • A vertical space defined by DesiredSkipAboveTitle is added before the title and a DesiredSkipBelowTitle is added after the title.
  • Need to run at least twice to get the tikz drawing in correct position.

Code:

%defUseBoxes{}% Uncomment to use boxes
documentclass{article}
usepackage{showframe}
usepackage{tikz}

usepackage[paperwidth=7.0cm]{geometry}

newcommand*{DesiredSkipAboveTitle}{5pt}
newcommand*{DesiredSkipBelowTitle}{10pt}

newcommand*{NumberOfTitleLines}{2}
newcommand*{Title}{A Title that Takes Up Two Lines}
newsavebox{TitleBox}
newcommand*{SetupTitleBox}[2]{%
    setbox#1vbox{%
        bfseriescentering%
        #2%
        %strut%
        par%
    }%
}

newcommand*{BodyTextLarge}{%
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Integer id nisl porta, porttitor tellus sed, sollicitudin erat. 
    Aliquam tellus urna, feugiat et tortor quis, aliquam mattis orci.% 
}%
newcommand*{BodyTextSmall}{%
    Small Text.% 
}%

newcommand{SelectedBodyText}{BodyTextLarge}
%newcommand{SelectedBodyText}{BodyTextSmall}


newsavebox{BodyBox}
newcommand{SetupBodyBox}[2]{%
    setbox#1vbox{%
        noindent#2%
        %strut%
    }%
}%

newlength{AdditionalSkip}
newcommand*{ShowTextGuideLines}[1]{%
begin{tikzpicture}[remember picture, overlay]
    coordinate (X) at ([
            xshift=1.0in+hoffset+oddsidemargin-0.3pt,
            yshift=-1.0in-voffset-topmargin-headheight-headsep,
        ]current page.north west);

    draw [draw=red, fill=yellow] (X) circle (2pt);%% DEBUGGING: Ensure (X) is the correct spot.

    setlength{AdditionalSkip}{DesiredSkipAboveTitle}%
    foreach X in {1, ..., #1} {%
        ifnumX>NumberOfTitleLines
            %% After title, need to adjust AdditionalSkip for space after title
            setlength{AdditionalSkip}{%
                dimexprDesiredSkipAboveTitle+DesiredSkipBelowTitlerelax%
             }%
        fi
        draw [thin, red] ([yshift=-Xbaselineskip-AdditionalSkip]X) -- ++ (hsize,0);
    }%

    tikzset{Node Style/.style={anchor=south, draw=red, inner sep=1pt}}
    ifdefinedUseBoxes
        node [Node Style, fill=yellow] at ([xshift=0.5hsize]X) {using boxes};
    else
        node [Node Style, fill=green] at ([xshift=0.5hsize]X) {Not using boxes};
    fi
end{tikzpicture}%
}%


begin{document}
    %% ---------------------------------------------------------- Set up the title and body
    SetupTitleBox{TitleBox}{Title}%
    SetupBodyBox{BodyBox}{SelectedBodyText}%
    %% ---------------------------------------------------------- Title
    hbox{}kern-topskip%% See https://tex.stackexchange.com/questions/7676/why-does-vspace0pt-add-vertical-space#comment12433_7681
    vspace*{DesiredSkipAboveTitle}%
    %%
    ifdefinedUseBoxes
        noindentusebox{TitleBox}%
        vspace*{DesiredSkipBelowTitle}%
        parnoindentusebox{BodyBox}%
    else
        noindent{bfseriescenteringTitlepar}%
        vspace*{DesiredSkipBelowTitle}%
        parnoindentSelectedBodyText%
    fi
    noindentShowTextGuideLines{7}%
end{document}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.