1

I have created a custom theorem-like environment using the package thmtools commands \declaretheoremstyle and \declaretheorem. The header of the environment is supposed to be given as an option at the point of use of the environment. The MWE given below defines the custom theorem-like environment custdef as an example of a custom theorem-like environment. The MWE defines the custom theorem with the header Pellentesque Habitant as an instance of the environment custdef. The MWE compiles. However, an unwanted space appears before the header in the typeset text.

Could someone advise me on how I could get rid of the unwanted space. The desired solution should work for any reasonable value of the option postheadspace. I would appreciate any help towards solving the problem.

MWE:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{nameref}

\makeatletter
\declaretheoremstyle[%
    spaceabove    = \topsep,%
    spacebelow    = \topsep,%
    notefont      = \bfseries,%
    bodyfont      = \normalfont\itshape,%
    headpunct     = .,%
    notebraces    = {}{},%
    postheadspace = 0.5em,%
    headindent    = \z@,%
    headformat    = \NOTE
]{CDStyle}

\declaretheorem[
    heading       = {},
    numbered      = no,
    refname       = \NOTE,
    preheadhook   = \vskip\z@,%
    postfoothook  = \vskip\z@,%
    style         = CDStyle
]{custdef}
\makeatother

\begin{document}
Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi
dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla.

\begin{custdef}[Pellentesque Habitant]
Pellentesque Habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas viverra metus rhoncus sem dictum gravida.
\end{custdef}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque.
\end{document}
3

The space is due to \thmt@space, that you can nullify with a suitable setting of preheadhook.

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{nameref}

\declaretheoremstyle[
    spaceabove    = \topsep,
    spacebelow    = \topsep,
    notefont      = \bfseries,
    bodyfont      = \normalfont\itshape,
    headpunct     = .,
    notebraces    = {}{},
    postheadspace = 0.5em,
    headindent    = 0pt,
    headformat    = \NOTE,
]{CDStyle}

\makeatletter
\declaretheorem[
    preheadhook   = \renewcommand{\thmt@space}{},
    numbered      = no,
    refname       = \NOTE,
    style         = CDStyle
]{custdef}
\makeatother

\begin{document}

\nameref{foo}

Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi
dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla.

\begin{custdef}[Pellentesque Habitant]\label{foo}
Pellentesque Habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas viverra metus rhoncus sem dictum gravida.
\end{custdef}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque.

\end{document}

enter image description here

4
  • Thanks @egreg. Your solution to the problem works perfectly for me. I had feared that the redefinition of the command \thmt@space would have a global effect. I have confirmed that the effect of the redefinition is, fortunately, localized to the environment custdef.
    – user24098
    Sep 6 '17 at 6:37
  • 1
    @user24098 That's the purpose of preheadhook. It may be a problem if you nest other statements, I didn't test.
    – egreg
    Sep 6 '17 at 8:19
  • Thanks once more @egreg. May I seek some clarification. You have specified \unskip\NOTE as the value of the option headformat in your declaration of CDStyle. Is the \unskip command necessary? I have noticed that its removal does not affect the typeset output. Does it have to be included to take care of a situation that is not covered by the MWE?
    – user24098
    Sep 6 '17 at 9:57
  • @user24098 Sorry, I forgot to remove it
    – egreg
    Sep 6 '17 at 10:31
1

You can hack and set the head indent to the – interwordspace. I took the liberty to slightly simplify you code, as title heading and  name are synonyms:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{nameref}

\makeatletter
\declaretheoremstyle[%
spaceabove = \topsep,%
spacebelow = \topsep,%
notefont = \bfseries,%
bodyfont = \normalfont\itshape,%
headpunct = .,%
notebraces = {}{},%
postheadspace = 0.5em,%
headindent =-\fontdimen2\font, %
headformat =\NOTE
]{CDStyle}

\declaretheorem[
numbered =no,
name = {},
refname =\NOTE,
preheadhook = \vskip\z@,%
postfoothook = \vskip\z@,%
style = CDStyle
]{custdef}
\makeatother

\begin{document}

Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi
dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur
auctor semper nulla.

\begin{custdef}[Pellentesque Habitant]
  Pellentesque Habitant morbi tristique senectus et netus et malesuada
  fames ac turpis egestas viverra metus rhoncus sem dictum gravida.
\end{custdef}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer
id, vulputate a, magna. Donec vehicula augue eu neque.

\end{document} 

enter image description here

Added (06/06)

This is simpler to obtain, without a hack, with package ntheorem: it has an empty theorem style, which prints only the optional argument. Unfortunately, it adds no separator after the optional argument. Fortunately, it has a \renewtheoremstyle command which allowed me to add a \labelseparator. So here is what you have to ad to your preamble to make ntheorem do what you want:

\makeatletter
\renewtheoremstyle{empty}%
{\item[]}%
{\item[\theorem@headerfont \hskip\labelsep\relax ##3\theorem@separator]}
\makeatother

\theoremstyle{empty}
\theoremprework{\labelsep=0.5em}
\theoremheaderfont{\upshape\bfseries}
\theorembodyfont{\itshape}
\theoremseparator{.\hspace{0.5em}}
\newtheorem{custdef}{}
4
  • Thanks for your solution and the modification that you made to my code. The appearance of synonymous option was an oversight on my part. Your code works for the given value of the option postheadspace. However, changing the value of the option to 0.7em or 0.9em, for example, changes the indentation of the header. What could be done to make the solution insensitive to changes in the value of postheadspace?
    – user24098
    Sep 6 '17 at 6:48
  • 1
    I'm afraid this is due to the way thmtools (or amsthm) manages the underlying list settings. All I could find with my solution was th add a factor > 1, say for postheadspace=0.9em, use headindent =-1.4\fontdimen2\font, but that's a hack. Fortunately, I suppose one doesn't change the value of headindent very often. This being say, this is quite simpler, and requires no hack, if you load ntheorem in the place of amsthm. I'll post a code in a moment.
    – Bernard
    Sep 6 '17 at 9:28
  • Thanks @Bernard for the solution based on the use of package ntheorem. I have tried it out. It works well and requires simpler code.
    – user24098
    Sep 6 '17 at 15:36
  • It has another advantage w.r.t. amsthm: the automatic placement of the end-of-theorem/proof symbol, even when the environment ends up in a multiline displayed equation. It also can cooperate with thmtools, with some restrictions.
    – Bernard
    Sep 6 '17 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.