Text FormattingCustom Section Error ("horizontal mode")

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Andreas Knafl
Posts: 11
Joined: Mon Jun 20, 2016 11:28 pm

Custom Section Error ("horizontal mode")

Post by Andreas Knafl »

Hey Guys!
I'm about to create my own section-Style an I've got a problem.
That's how I want my section look like:

Code: Select all

\documentclass[a5paper,10pt,twoside,]{scrbook}
\usepackage[left=2cm,right=1cm,top=1cm,bottom=0.5cm,includeheadfoot]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsfonts}
\usepackage{amsmath}


\usepackage{tabularx}
\usepackage{titlesec}

\renewcommand{\thesection}{\setcounter{section}{1}\arabic{section}}

\titleformat{\section}
{\normalfont\rmfamily\mdseries}
{}{2pt}{}  [
  ]

\newcommand\Section[2]{
\begin{center}
\begin{tabularx}{\textwidth}{lXr}
\thesection & & #1 \\ \hline
 & & \fontsize{6}{0} \selectfont #2
\end{tabularx}
\end{center}
}

\begin{document}



\Section{Text1}{Text two}


Test
\Section{Text2}{test}
Test

\end{document}

When I don't use \section*{#1}, Latex wont continue the numbering of my section, and they also doesn't appeare in the toc

So when I use \section*{#1},....

Code: Select all

\documentclass[a5paper,10pt,twoside,]{scrbook}
\usepackage[left=2cm,right=1cm,top=1cm,bottom=0.5cm,includeheadfoot]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsfonts}
\usepackage{amsmath}


\usepackage{tabularx}
\usepackage{titlesec}

\renewcommand{\thesection}{\setcounter{section}{1}\arabic{section}}

\titleformat{\section}
{\normalfont\rmfamily\mdseries}
{}{2pt}{}  [
  ]

\newcommand\Section[2]{
\begin{center}
\begin{tabularx}{\textwidth}{lXr}
\thesection & & \section{#1} \\ \hline   %there I use \section*{}
 & & \fontsize{6}{0} \selectfont #2
\end{tabularx}
\end{center}
}

\begin{document}



\Section{Text1}{Text two}


Test
\Section{Text2}{test}
Test

\end{document}

..., there will be an error telling me I'm in the wrong mode (horizontal/vertical)

I'm working on this problem for 3 days

May somebody can solve my problem?

Thanks for helping!!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Custom Section Error ("horizontal mode")

Post by Johannes_B »

Are you just not using \chapter here, because it is irrelevant, or don't you know about the chapter command?
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Andreas Knafl
Posts: 11
Joined: Mon Jun 20, 2016 11:28 pm

Custom Section Error ("horizontal mode")

Post by Andreas Knafl »

Johannes_B wrote:Are you just not using \chapter here, because it is irrelevant, or don't you know about the chapter command?
Hi Johannes_B!
My chapter command is already defined. In that case, everything went fine.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Custom Section Error ("horizontal mode")

Post by Johannes_B »

Took me some time to find a suitable solution. I hope it is ok.

Code: Select all

\documentclass[10pt,twoside,]{scrbook}
\usepackage[left=2cm,right=1cm,top=1cm,
	bottom=1cm,
showframe,%Better see the type area
	includeheadfoot,paper=a5paper,
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsfonts}
\usepackage{amsmath}


\usepackage{blindtext}
\usepackage{tabularx}
\usepackage[explicit]{titlesec}

\renewcommand{\thesection}{\arabic{section}}

\titleformat{\section}{}{}{0pt}{}{}



\makeatletter
\newcommand\Section[2]{
	\section{#1}
	\noindent\begin{tabularx}{\linewidth}{@{}l>{\raggedleft\arraybackslash}X@{}}
		\usekomafont{disposition}\usekomafont{section}\thesection&%
		\usekomafont{disposition}\usekomafont{section}#1\\\hline
	&\fontsize{6}{8}\selectfont #2 
\end{tabularx}\bigbreak\@afterheading
}
\makeatother

\begin{document}



\Section{Wombat}{a cute guy}

\blindtext

\Section{Capybaras are sooo cute}{wow, it's big}

\blindtext

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Andreas Knafl
Posts: 11
Joined: Mon Jun 20, 2016 11:28 pm

Custom Section Error ("horizontal mode")

Post by Andreas Knafl »

Johannes_B wrote:Took me some time to find a suitable solution. I hope it is ok.

Code: Select all

\documentclass[10pt,twoside,]{scrbook}
\usepackage[left=2cm,right=1cm,top=1cm,
	bottom=1cm,
showframe,%Better see the type area
	includeheadfoot,paper=a5paper,
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsfonts}
\usepackage{amsmath}


\usepackage{blindtext}
\usepackage{tabularx}
\usepackage[explicit]{titlesec}

\renewcommand{\thesection}{\arabic{section}}

\titleformat{\section}{}{}{0pt}{}{}



\makeatletter
\newcommand\Section[2]{
	\section{#1}
	\noindent\begin{tabularx}{\linewidth}{@{}l>{\raggedleft\arraybackslash}X@{}}
		\usekomafont{disposition}\usekomafont{section}\thesection&%
		\usekomafont{disposition}\usekomafont{section}#1\\\hline
	&\fontsize{6}{8}\selectfont #2 
\end{tabularx}\bigbreak\@afterheading
}
\makeatother

\begin{document}



\Section{Wombat}{a cute guy}

\blindtext

\Section{Capybaras are sooo cute}{wow, it's big}

\blindtext

\end{document}
Thank you very much for the Help!
Right now I'm not able to understand your code. May I will be allowed to ask some questions, when I promise to work the smart way ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Custom Section Error ("horizontal mode")

Post by Johannes_B »

Of course you are allowed to ask for clarification. That is my standard signature that appears under all my posts. ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Custom Section Error ("horizontal mode")

Post by Johannes_B »

An even better version with respect to the optional argument.

Code: Select all

\documentclass[10pt,twoside,]{scrbook}
\usepackage[left=2cm,right=1cm,top=1cm,
	bottom=1cm,
showframe,%Better see the type area
	includeheadfoot,paper=a5paper,
]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsfonts}
\usepackage{amsmath}


\usepackage{blindtext}
\usepackage{tabularx}
\usepackage[explicit]{titlesec}


\titleformat{\section}{}{}{0pt}{}{}



\usepackage{xparse}
\makeatletter
\NewDocumentCommand{\Section}{ o m m }{
	\IfNoValueTF{#1}{\section{#2}}{\section[#1]{#2}}
	\noindent\begin{tabularx}{\linewidth}{@{}l>{\raggedleft\arraybackslash}X@{}}
		\usekomafont{disposition}\usekomafont{section}\thesection&%
		\usekomafont{disposition}\usekomafont{section}#2\\\hline
	&\fontsize{6}{8}\selectfont #3 
\end{tabularx}\bigbreak\@afterheading
}
\makeatother
\renewcommand{\thesection}{\arabic{section}}

\begin{document}

\tableofcontents

\Section{Wombat}{a cute guy}

\blindtext

\Section{Capybaras are sooo cute}{wow, it's big}

\blindtext

\Section[i am in the toc]{Ever heard of Maras?}{It's a species of
the cavy family}

\blindtext
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply