2

I would like to make a blue square with corresponding subsection number.

For this I done:

\setsecnumformat{\csname #1secnumformat\endcsname}
\newcommand\subsectionsecnumformat{
    \colorbox{MidnightBlue}{
        \makebox[.7cm] {
            \color{white}\thesubsection
        }
    }
    \hspace{0.5cm}
}

This build fine but the height box change if I use alpha character as numbering. Indeed letter 'a' is smaller than 'b'. So I replaced makebox by minipage to control vertical space. As follow:

\setsecnumformat{\csname #1secnumformat\endcsname}
\newcommand\subsectionsecnumformat{
    \colorbox{MidnightBlue}{
        \begin{minipage}[c][0.7cm]{.7cm}
            \color{white}\thesubsection
        \end{minipage}
    }
    \hspace{0.5cm}
}

This do not build. Any help/suggestion are welcome.

Best regards

1 Answers1

3

Adding a \strut to your first code ensures the same size. If you wanted to set the height to a lower value, you should replace \makebox with a \parbox, where you can control the height and width of the box. The syntax is \parbox[verticalPos][height][horisontalPos]{width}{text}. Example \parbox[b][.8ex][l]{.7em}{text}

\documentclass[11pt]{memoir}
\usepackage[dvipsnames]{xcolor}
\setsecnumformat{\csname #1secnumformat\endcsname}
\newcommand\subsectionsecnumformat{
    \colorbox{MidnightBlue}{
        \makebox[.7cm]{\strut%
            \color{white}\thesubsection
        }
    }
    \hspace{0.5cm}
}
\begin{document}
\subsectionsecnumformat
%\subsection{foo}
\end{document}
Runar
  • 6,082