3

I renewed my section with dot and I want to get a number without dot when I use \ref{}. How can I do it?

\documentclass[11pt]{article}
\renewcommand\thesection{\normalsize{\arabic{section}.}}
\begin{document}
\section{Introduction} \label{s-1}
I want to print just a number of Section \ref{s-1} without dot.
\end{document}

enter image description here

Mico
  • 506,678
  • 3
    Rather not renew that command and use one of these suggestions: https://tex.stackexchange.com/questions/24439/how-to-add-a-dot-after-the-section-number – nhck Oct 15 '20 at 12:01
  • Another reason not to renew \thesection to have the dot is that the default \thesubsection would then have two dots: "Subsection 1..1". – Teepeemm Oct 15 '20 at 13:53

3 Answers3

3

Here's a solution that doesn't require any external LaTeX packages.

enter image description here

\documentclass[11pt]{article}
%% Do _not_ do this:
%\renewcommand\thesection{\normalsize{\arabic{section}.}}

%% Instead, do this: % Method proposed in "The LaTeX Companion", 2nd ed. \makeatletter \def@seccntformat#1{@ifundefined{#1@cntformat}% {\csname the#1\endcsname\space}% default {\csname #1@cntformat\endcsname}}% enable individual control \newcommand\section@cntformat{\thesection.\space} % section-level \makeatother

\begin{document} \section{Introduction} \label{s-1} I can cross-reference the number of Section \ref{s-1} without a trailing dot. \end{document}

Mico
  • 506,678
2

Rather than change the meaning of \thesection, I leave it as is, without the dot, and change the manner that the section heading is output, by specifying a suffix to be appended to \thesection, for example.

\documentclass[11pt]{article}
%\renewcommand\thesection{\normalsize{\arabic{section}.}}
\makeatletter
%% SECTIONING \hskip'S BEFORE SECTIONING TITLES
\def\sectionkern      {1em}
\def\subsectionkern   {1em}
\def\subsubsectionkern{1em}
\def\paragraphkern    {1em}
%% SUFFIX ADDED TO \the SECTIONING MACROS
\def\sectionsuffix      {.}
\def\subsectionsuffix   {}
\def\subsubsectionsuffix{}
\def\paragraphsuffix    {}
%% SECTIONING LABEL: \the[section]\[section]suffix\hskip\[section]kern
\renewcommand\@seccntformat[1]{\normalsize\csname the#1\endcsname%
  \csname#1suffix\endcsname\hskip\csname#1kern\endcsname\relax}
\makeatother
\begin{document}
\section{Introduction} \label{s-1}
I want to print just a number of Section \ref{s-1} without dot.
\end{document}

enter image description here

2

You have a very simple solution with titlesec, which adds a dot for all section levels, and doesn't modify \thesection & al.

\documentclass[11pt]{article}
\usepackage{titlesec}
\titlelabel{\thetitle. }

\begin{document}

\section{Introduction} \label{s-1} I want to print just a number of Section \ref{s-1} without dot.

\end{document}

enter image description here

Bernard
  • 271,350
  • This approach prints subsection numbers as, for example, 1.1., with a trailing dot. Is that a common format? – Steven B. Segletes Oct 15 '20 at 18:51
  • I think I've already seen it. Whether it's common, I couldn't say. Other that, one would have to use the advanced interface of titlesec to enable the final dot for sections only. – Bernard Oct 15 '20 at 19:35