1

I'm dealing with memoir class trying to create an own fancy chapter style for a project. I'm currently using TikZ and got some good advance. The issue, however, is a black box/line which does not vanish at all.

Here's the MWE:

\documentclass[a4paper,12pt,extrafontsizes,twoside,onecolumn,openany,draft]{memoir}

\setlrmarginsandblock{2.5cm}{2.5cm}{*}
\setulmarginsandblock{2.5cm}{2.5cm}{*}
\checkandfixthelayout

\usepackage{tikz}
\usepackage{color,calc}
\usepackage{lipsum}

\makeatletter
\renewcommand{\@chapapp}{Lição}

\newcommand*\BuildChpNumb[1]{%
    \begin{tikzpicture}
        \draw [-, rounded corners, thick, purple] (0,2) -- (0,0) -- (\textwidth,0) -- (\textwidth,2);
        \node at (\textwidth - 200,1) {\chaptitlefont #1};
    \end{tikzpicture}
}
\makechapterstyle{Filipe}{%
    \renewcommand{\chapnamefont}{\large\scshape}
    \renewcommand{\chapnumfont}{\Huge\bfseries}
    \renewcommand{\chaptitlefont}{\Huge\bfseries}
    \setlength{\beforechapskip}{0pt}
    \setlength{\midchapskip}{0pt}
    \setlength{\afterchapskip}{0pt}
    \renewcommand{\printchaptername}{}
    \renewcommand{\chapternamenum}{}
    \renewcommand{\printchapternum}{}
    \renewcommand{\afterchapternum}{}
    \renewcommand{\afterchaptertitle}{}
    \renewcommand{\printchaptertitle}[1]{%
        \BuildChpNumb{##1}\par
    }%
}
\chapterstyle{Filipe}
\makeatother

\begin{document}

\chapter{A MWE}
    \section{Introduction}
        \lipsum[1-5]
    \section{History of the MWE}
        \lipsum[6-10]

\end{document}

And the result comes out with this damn line just in the rightside of the header box.

MWE Faulty

How to get rid of it?

1
  • 1
    Is it designed to be too wide on purpose? The tikz picture is wider than the text width, how much should be listed in the log (not at pc so cannot test). The width of the image is probably text width plus the width of the thick line (one half on each side). Haw you thought about what the style should do if the title is long?
    – daleif
    Jul 19, 2017 at 15:42

4 Answers 4

2

I believe that it's because of draft definition in memoir. If you put final instead of draft, it should disappear.

EDIT: After some research it's a margin warning that shows only in draft mode.

2
  • That did the culprit. But, what would be the best option (good-practice speaking): change the class' definition to final or to correct the margin to get rid of the warning? Jul 19, 2017 at 17:14
  • Definitely I would say to correct the margin, just in good measure. Good luck! Jul 20, 2017 at 8:04
1

Tiago Correia already explained that the black bar marks an overfull box. To get rid of it, you could make your chapter decoration a tiny bit smaller by not going all the way to \textwidth but just .99\textwidth.

\documentclass[a4paper,12pt,extrafontsizes,twoside,onecolumn,openany,draft]{memoir}

\setlrmarginsandblock{2.5cm}{2.5cm}{*}
\setulmarginsandblock{2.5cm}{2.5cm}{*}
\checkandfixthelayout

\usepackage{tikz}
\usepackage{color,calc}
\usepackage{lipsum}

\makeatletter
\renewcommand{\@chapapp}{Lição}

\newcommand*\BuildChpNumb[1]{%
    \begin{tikzpicture}
        \draw [-, rounded corners, thick, purple] (0,2) -- (0,0) -- (.99\textwidth,0) -- (.99\textwidth,2);
        \node at (.99\textwidth - 200,1) {\chaptitlefont #1};
    \end{tikzpicture}
}
\makechapterstyle{Filipe}{%
    \renewcommand{\chapnamefont}{\large\scshape}
    \renewcommand{\chapnumfont}{\Huge\bfseries}
    \renewcommand{\chaptitlefont}{\Huge\bfseries}
    \setlength{\beforechapskip}{0pt}
    \setlength{\midchapskip}{0pt}
    \setlength{\afterchapskip}{0pt}
    \renewcommand{\printchaptername}{}
    \renewcommand{\chapternamenum}{}
    \renewcommand{\printchapternum}{}
    \renewcommand{\afterchapternum}{}
    \renewcommand{\afterchaptertitle}{}
    \renewcommand{\printchaptertitle}[1]{%
        \BuildChpNumb{##1}\par
    }%
}
\chapterstyle{Filipe}
\makeatother

\begin{document}

\chapter{A MWE}
    \section{Introduction}
        \lipsum[1-5]
    \section{History of the MWE}
        \lipsum[6-10]

\end{document}
2
  • Thanks for the technical instruction. The objective is to indeed get the box on full width. I don't know if by making a little bit smaller (to .99\textwidth) would affect the alignment. @Tiago Correia 's answer also did the culprit, but, if you could, please enlighten me if by having an overfull box would be a wrong practice somehow. Thanks in advance. Jul 19, 2017 at 17:12
  • @FilipeFonseca If you use \textwidth and have lines thicker then 0 your decoration is larger then the surrounding text, so not aligned. Jul 20, 2017 at 11:02
1

Maybe you like different definition of your chapter style:

\documentclass[a4paper,12pt,extrafontsizes,twoside,onecolumn,openany,draft]{memoir}

\setlrmarginsandblock{2.5cm}{2.5cm}{*}
\setulmarginsandblock{2.5cm}{2.5cm}{*}
\checkandfixthelayout

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{color}
\usepackage{lipsum}

\makeatletter
%\renewcommand{\@chapapp}{Lição}

\newcommand*\BuildChpNumb[1]{% changed definition
    \begin{tikzpicture}
        \node[name=chapter, inner sep=0pt,
              text width=\dimexpr\textwidth-2pt\relax,
              minimum height=2cm,
              align=center, font=\chaptitlefont]  {#1};
        \path[draw=purple, rounded corners, line width=1pt]
        (chapter.north west) |- (chapter.south) -| (chapter.north east);
    \end{tikzpicture}
}
\makechapterstyle{Filipe}{%
    \renewcommand{\chapnamefont}{\large\scshape}
    \renewcommand{\chapnumfont}{\Huge\bfseries}
    \renewcommand{\chaptitlefont}{\Huge\bfseries}
    \setlength{\beforechapskip}{0pt}
    \setlength{\midchapskip}{0pt}
    \setlength{\afterchapskip}{0pt}
    \renewcommand{\printchaptername}{}
    \renewcommand{\chapternamenum}{}
    \renewcommand{\printchapternum}{}
    \renewcommand{\afterchapternum}{}
    \renewcommand{\afterchaptertitle}{}
    \renewcommand{\printchaptertitle}[1]{%
        \BuildChpNumb{##1}\par
    }%
}
\makeatother

\begin{document}
\chapterstyle{Filipe}

\chapter{A MWE}
    \section{Introduction}
        \lipsum[1-5]
    \section{History of the MWE}
        \lipsum[6-10]

\end{document}

enter image description here

1

You don't need to guess how much you need to shrink the box. Latex LaTeX tells you, if you look at the output or the log file:

Overfull \hbox (0.79999pt too wide) in paragraph at lines 41--41

You are specifying the position of the center of the purple line, not its outside edge. The line is 0.8pt wide, and the center of the line is 0.4pt away from the edge. You need to move the center of the line in by 0.4pt on each side, so the outside edges are exactly \textwidth apart.

Also, you should center the text accurately, not with a "guess" at the position like \textwidth - 200. if you want position the center of the text at "half the \textwidth", then say so!

\newcommand*\BuildChpNumb[1]{%
    \begin{tikzpicture}
        \draw [-, rounded corners, thick, purple] (0.4pt,2) -- (0.4pt,0) -- (\textwidth-0.4pt,0) -- (\textwidth-0.4pt,2);
        \node at (0.5\textwidth,1) {\chaptitlefont #1};
    \end{tikzpicture}
}

You could ignore this and get rid of the black bar by changing the draft option in memoir to final. Most people won't notice an alignment error in the purple line of only 0.8pt. But personally I always try to fix these problems properly so they don't give warning messages - and that is easy to do.

1
  • Thanks for information. Actually the "-200" was just to give a better overview of the black box. The intention is to make the text right aligned, included as a tikz node, as \node [align=right,left] at (\textwidth,0.5) {#1};. Anyway, since it's a good practice to get rid of those warnings, I'll do the proposed changes. Jul 19, 2017 at 18:58

You must log in to answer this question.

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