Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I decided to write my first own latex class that has to reproduce template used for some intenal type of documents made in word. I cannot find how to do one thing. In the template, all standard text (as well as lists etc.) are slightly intended, while heading remain not intended. You can do it with a hangindent, but only for one paragraph. How to define in my own class, that such a behaviour is standard for all the normal text?

I would not like to use any external classes...

share|improve this question
1  
Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. It is considered a lot better to put in some code that will compile, as it makes it a lot easier for us to copy it into our text editor and work with it, and see exactly what it is you are trying to do. –  hpesoj626 Oct 29 '12 at 5:51
1  
It's the other way around: the section headers should have a negative indentation. –  egreg Oct 29 '12 at 11:55
add comment

2 Answers

Here is a partial solution. It uses How can I change the margins for only part of the text? to indent all the text, and Customizing indentation in section and subsection headings to adjust the section headings so that they are not indented (required the titlesec package). Here is a before and after comparrison:

Before: enter image description here

After: enter image description here

Notes:

  • I labelled this as partial only because I could not unindent the section headings without the use of the titlesec package. One of the following should worked but I do not know why they do not:

    \def\section#1{\hspace*{-\LeftMargin}\OldSection{#1}}
    

    or

    \def\section#1{\endChangeMargin\OldSection{#1}\ChangeMargin{\LeftMargin}{\RightMargin}}
    

    I have posted a follow-up question to see why this is occurring: Unindent section headings.

    There is also a slight vertical spacing issue with the section heading but I think that is related to messing with the section heading as it is more apparent with my failed attempts to unindent the section headings.

  • The showframe package was used just to show the page margins.

  • The lipsum package was used just to provide dummy text.

Code:

\documentclass{article}
\usepackage{titlesec}
\usepackage{showframe}
\usepackage{lipsum}

\newcommand*{\LeftMargin}{0.5cm}%
\newcommand*{\RightMargin}{0.0cm}%


%% http://tex.stackexchange.com/questions/588/how-can-i-change-the-margins-for-only-part-of-the-text
\def\ChangeMargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]}%
\let\endChangeMargin\endlist%
\AtBeginDocument{\ChangeMargin{\LeftMargin}{\RightMargin}}
\AtEndDocument{\endChangeMargin}

%% Not sure why these did not work
%\let\OldSection\section
%\def\section#1{\hspace*{-\LeftMargin}\OldSection{#1}}%
%\def\section#1{\endChangeMargin\OldSection{#1}\ChangeMargin{\LeftMargin}{\RightMargin}}%

%% http://tex.stackexchange.com/questions/25082/customizing-indentation-in-section-and-subsection-headings
\titlelabel{\hspace*{-\LeftMargin}\thetitle~}


\begin{document}
\lipsum*[1-3]
Here is a list:
\begin{enumerate}
    \item First item
    \item Second item
\end{enumerate}
\section{Section Name}
\lipsum[1-3]
\end{document}
share|improve this answer
    
Thanks! This is exactly what I need. However, there is a small problem with my custom section heading and the indentation. If The section heading spans over more then one line, the second line of the heading is as intended as the normal text: imgur.com/5CDli. –  LWP Oct 29 '12 at 8:03
    
Uhm, I am not sure how should I properly insert the code in the comment, but it is: \renewcommand{\section}{\@startsection {section}% % the name {1}% % the level {-5mm}% % the indent {-\baselineskip}% % the before skip {0.5\baselineskip}% % the after skip {\large\color{red}\uppercase}% } % the style \setcounter{secnumdepth}{0} –  LWP Oct 29 '12 at 8:06
    
For that you should refer to the follow up question: Unindent section headings. –  Peter Grill Oct 29 '12 at 17:29
    
OK, so far I pasted \def\@seccntformat#1{\protect\hspace*{-\LeftMargin}{\csname the#1\endcsname\quad}} in my class and it does not change anything. But I am a complete beginner in terms of latex classes writing, so I guess I need to get some more reading... –  LWP Oct 30 '12 at 2:43
    
That should work. Perhaps you need to surround it with a \makeatletter, \makeatother. You don't this is package files, but perhaps you do in .cls files. –  Peter Grill Oct 30 '12 at 3:06
add comment

I don't know if I fully understand your question. A minimal working example as I have indicated in my comment will greatly aid in understanding your problem.

Do you want to remove all indentations? Then parskip package is what you are looking for. Look at Is there an easy way to have my whole document with a space between paragraphs rather than indentation?. Just write

\usepackage{parskip}

in your preamble.

Do you want your first paragraphs indented? Then use the package indentfirst by writing

\usepackage{indentfirst}

in your preamble.

If you want your class to load one of the two packages as your case may be, then write one of

\RequirePackage{parskip}

or

\RequirePackage{indentfirst}

in your .cls file.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.