General ⇒ Define my own section style
-
- Posts: 1
- Joined: Fri Oct 03, 2008 1:01 am
Define my own section style
I am looking at my hw and wondering how to define make headings like The "Problem x.x". I'd imagine there is a way to do sth like: \problem{} and then latex will automatically number it for me.
http://inst.eecs.berkeley.edu/~cs281a/f ... /home2.pdf
It seems the only way to learn latex is to learn by examples. Any better ideas?
Thank you.
Outdateboy
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
-
- Posts: 707
- Joined: Tue Mar 25, 2008 5:02 pm
Define my own section style
The \newcounter command takes one required and one optional argument. The required argument is the name of the counter by which you will refer to it later. The optional argument refers to another counter; incrementing this counter will reset the old counter. For example, \newcounter{prob}[set] resets prob to zero every time set gets increased. This is useful if, for example, your equation counter gets reset each chapter (such as Eq. (3.2), where it should go back to (4.1) at the beginning of chapter 4).
There are several standard counters: chapter, section, equation, subsection, part, subsubsection, figure, table, etc.
I've included some code that demonstrates the newcounter and stepcounter commands.
Code: Select all
\documentclass{article}
\begin{document}
\newcounter{set}
\setcounter{set}{2}
\newcounter{problem}[set]
\newcommand{\problem}{\refstepcounter{problem}{\vspace{2\baselineskip}\noindent\large \bfseries Problem~\arabic{set}.\arabic{problem}}\\}
\problem
\textit{Sum-product algorithm:} Consider the sum-product\ldots.
\problem
\textit{Max-marginals:} Consider the max-marginals\ldots.
\stepcounter{problem}
\problem
Demonstraction of \verb"\stepcounter"
\addtocounter{problem}{-1}
\problem
Counter increments can be negative!
\end{document}
There are many sites where you can look up references to specific LaTeX commands and/or concepts. My personal favorite is http://www-h.eng.cam.ac.uk/help/tpl/tex ... ltx-2.html
There's also a great introduction that explains many of these topics at http://tug.ctan.org/info/lshort/english/lshort.pdf
Define my own section style
Code: Select all
\documentclass{report}
\usepackage{amsthm}
%definition of the new style
\newtheoremstyle{problem}% name
{6pt}% Space above
{6pt}% Space below
{}% Body font
{}% Indent amount
{\bfseries}% Theorem head font
{}% Punctuation after theorem head
{\newline}% Space after theorem head
{}% Theorem head spec
%declaring the style to be used
\theoremstyle{problem}
%declaring the new theorem-like structure and declaring that
%it should be numbered within chapters
\newtheorem{prob}{Problem}[chapter]
\begin{document}
\chapter{Dummy chapter}
\begin{prob}
This is the first test problem of chapter one text text text
\end{prob}
\begin{prob}
This is the second test problem of chapter one text text text
\end{prob}
\chapter{Another dummy chapter}
\begin{prob}
This is the first test problem of chapter two text text text
\end{prob}
\end{document}