Here's a way for switching between sections with tighter spacing and sections with normal spacing, done by redefing the \section
command of scrartcl:
\documentclass{scrartcl}
\newcommand{\breaksection}[1]{#1\par\noindent}
\usepackage{letltxmacro}
\LetLtxMacro{\oldsection}{\section}
\makeatletter
\newcommand*{\smallsection}{
\renewcommand{\section}{\@startsection{section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{0ex}%
{\ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
\setlength{\parfillskip}{\z@ plus 1fil}\fi
\raggedsection\normalfont\sectfont\nobreak\size@section\breaksection}%
}
}
\makeatother
\newcommand*{\stdsection}{\LetLtxMacro{\section}{\oldsection}}
\begin{document}
\section{One}
text
\smallsection
\section{Two}
text
\stdsection
\section{Three}
text
\end{document}
It copies the original definition from scrartcl but uses 0ex
for the new space after the heading, which is 2.3ex \@plus.2ex
by default. \breaksection
is defined to get a paragraph break after the heading, without it you would get a run-in heading: a positive value causes a skip below, a negative value a run-in heading with that horizontal space.
Here is a tikz
way using scale=<fraction>
in the options of the \node
itself.
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw, fill=yellow!20, rectangle, align=left, inner sep=0.5ex, font=\sffamily] (a) at (0,0)
{ Abc \\ Def \\ Ghi };
\node[draw, fill=yellow!20, rectangle, align=left, inner sep=0.5ex, font=\sffamily,scale=0.8,right=0.5cm of a] (b)
{ Abc \\ Def \\ Ghi };
\node[draw, fill=yellow!20, rectangle, align=left, inner sep=0.5ex, font=\sffamily,scale=0.6,right=0.5cm of b] (c)
{ Abc \\ Def \\ Ghi };
\node[draw, fill=yellow!20, rectangle, align=left, inner sep=0.5ex, font=\sffamily,scale=0.4,right=0.5cm of c] (d)
{ Abc \\ Def \\ Ghi };
\node[draw, fill=yellow!20, rectangle, align=left, inner sep=0.5ex, font=\sffamily,scale=0.2,right=0.5cm of d] (e)
{ Abc \\ Def \\ Ghi };
\end{tikzpicture}
\end{document}
Best Answer
Normally you should be able to define stretchable "rubber" glue that automatically adjusts to the available space however if you really need to take different action depending on the number of lines you can do that as follows:
Note the blank line (or an equivalent command) before the test is needed so the paragraph is completed and
\prevgraf
updated with the number of lines in the previous paragraph.