5

I want to appear statement "Def 1.1.1-" instead of "Def 1.1.1." I use Texlive 2017 and the following codes:

 \documentclass{report}
    \usepackage{amsthm}
    %\usepackage{hyperref}
    \makeatletter
    \def\@thm#1#2#3{%
        \ifhmode\unskip\unskip\par\fi
        \normalfont
        \trivlist
        \let\thmheadnl\relax
        \let\thm@swap\@gobble
        \thm@notefont{\fontseries\mddefault\upshape}%
        \thm@headpunct{-}
        \thm@headsep 5\p@ plus\p@ minus\p@\relax
        \thm@space@setup
        #1% style overrides
        \@topsep \thm@preskip              
        \@topsepadd \thm@postskip      
        \def\@tempa{#2}\ifx\@empty\@tempa
        \def\@tempa{\@oparg{\@begintheorem{#3}{}}[]}%
        \else
        \refstepcounter{#2}%
        \def\@tempa{\@oparg{\@begintheorem{#3}{\csname the#2\endcsname}}[]}%
        \fi
        \@tempa
    }
    \makeatother
    \theoremstyle{definition}
    \newtheorem{definition}{ِDef}[section]
    \begin{document}
    \chapter{TEST}
    \section{Introduction}
    \begin{definition}
        content...
    \end{definition}
    \end{document}

But when I use hyperref package, output is "Def 1.1.1." Can you help me?

  • The trailing - looks awkward, in my point of view – user31729 Dec 7 '17 at 7:03
  • Since you're loading the amsthm package, would you want to create a solution that makes use of this package's machinery? – Mico Dec 7 '17 at 7:32
8

I suggest to use a special theorem style rather than explicitly changing \@thm which is the base macro for all theorems definitions, meaning any theorem will have the same settings unless explicitly changed with \theoremstyle later on.

Change the spacings at will, the given 3pt values are just the usual values from the amsthm manual.

I find the trailing - at the end of the theorem number weird, however, but this is my opinion only.

\documentclass{report}

\usepackage{amsthm}
\usepackage{hyperref}

\newtheoremstyle{dashed}{3pt}{3pt}{\fontseries\mddefault\upshape}{}{\bfseries\itshape}{-}{3pt}{}

\theoremstyle{dashed}
\newtheorem{definition}{ِDef}[section]

\begin{document}
\chapter{TEST}
\section{Introduction}
\begin{definition}
    content...
\end{definition}
\end{document}

enter image description here

4

Here's a solution for users of the ntheorem package.

\documentclass{report}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}
\usepackage[colorlinks]{hyperref} % optional
\usepackage[nameinlink]{cleveref} % optional

\theoremstyle{plain}
\theoremseparator{-} 
\theorembodyfont{\upshape}
\newtheorem{definition}{ِDef}[section]
\crefname{definition}{definition}{definitions}

\begin{document}
\setcounter{chapter}{1} % just for this example
\setcounter{section}{1}

\begin{definition} \label{def:dash}
    content...
\end{definition}
A cross-reference to \cref{def:dash}.
\end{document}

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.