5

I want to add two rule before and after \tenbai. Can somebody help me?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{vietnam}
\newcounter{sobai}
\newcommand{\tenbai}[1]{
    \addtocounter{sobai}{1}
    \textbf{\centerline{\huge{\S\thesobai. #1}}}
    \addcontentsline{toc}{section}{\S\thesobai. #1}
}


\begin{document}

    \tenbai{Số phức và tính toán đại số}
\end{document}
  • 3
    Be aware of spurious spaces in your definition. See What is the use of percent signs (%) at the end of lines? – Werner Jan 14 at 17:24
  • 1
    Maybe this helps: \documentclass{article} \usepackage[utf8]{vietnam} \newcounter{sobai} \newcommand{\tenbai}[1]{% \stepcounter{sobai}% \par\noindent\hrulefill \begin{center} \huge\bfseries \S\thesobai.~#1% \addcontentsline{toc}{section}{\S\thesobai.~#1}% \end{center} \hrulefill\par } \begin{document} \tenbai{Số phức và tính toán đại số} \end{document} (each % is immediately followed by an end-of-line). Maybe it would be better to use for instance titlesec and redefine the appearance of sections. – frougon Jan 14 at 17:34
3

Here is an option - setting the header inside a tabular that spans the entire \linewidth:

enter image description here

\documentclass{article}

\usepackage[utf8]{vietnam}

\newcounter{sobai}
\newcommand{\tenbai}[1]{%
  \par
  \stepcounter{sobai}%
  \noindent
  \begin{tabular}{@{} p{\linewidth} @{}}
    \hline \hline
    \hfill\bfseries\huge\strut \S\thesobai. #1\hfill\mbox{} \\
    \hline \hline
  \end{tabular}%
  \addcontentsline{toc}{section}{\S\thesobai. #1}%
  \par\nobreak
}

\begin{document}

\tenbai{Số phức và tính toán đại số}

\end{document}
4

I would use standard tools such as titlesec.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{vietnam}
\usepackage{titlesec}

\usepackage{lipsum}% mock text

\titleformat{\section}
 {\huge\bfseries\filcenter\titlerule}
 {\S\thesection.}
 {0.33333em}
 {}
 [\titlerule]

\begin{document}

\lipsum[2]

\section{Số phức và tính toán đại số}

\lipsum[3]

\section{Số thực}

\lipsum[4]

\end{document}

enter image description here

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.