1

I've got a litte problem in making my own headings, my goal is something like this: Number, Heading, Text

my current code looks like this

%-- Preamble ------------------------------------
\documentclass[10pt,a4paper,twoside]{article}

%-- Nur für Debugging
%    \usepackage{showframe}
\usepackage{blindtext}

%-- Import packages -----------------------------
% Anpassung an deutsche Sprache
% Umlaute ----------------------------------------------------------------------
%   Umlaute/Sonderzeichen wie äüöß direkt im Quelltext verwenden (CodePage).
%   Erlaubt automatische Trennung von Worten mit Umlauten.
% ------------------------------------------------------------------------------
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}


% Seitenränder und Zeilenabstände
\usepackage{geometry}
\usepackage{setspace}

% Schriften und Farben
\usepackage{color}
\usepackage{colortbl} % Für farbige Tabellen
\usepackage[default,osfigures,scale=1]{opensans}

% Textumgebungen
\usepackage{multicol} % Text in mehreren Kolumnen darstellen

% Hyperrefs und PDF Information
\usepackage{hyperref}

% Tabellen
\usepackage{booktabs}

% Inhaltsverzeichnis umbenennen
\usepackage{tocbibind}

% Listen
\usepackage[ampersand]{easylist} % Einfache Liste Umgebung
% http://en.wikibooks.org/wiki/LaTeX/List_Structures

% Kopf und Fusszeilen
\usepackage{fancyhdr}

% Grafiken und Textbausteine
\usepackage[absolute]{textpos} % Absolue Positionierung
%    \usepackage[dvips,final]{graphicx} % Einbinden von JPG-Grafiken ermöglichen für
%dvi format
\usepackage[pdftex]{graphicx}
\usepackage{graphics} % keepaspectratio
\usepackage{floatflt} % zum Umfließen von Bildern
\graphicspath{{pictures/}} % hier liegen die Bilder des Dokuments

% Mathe
\usepackage{amsmath}
\usepackage{amssymb}

% Acronym Support
\usepackage[printonlyused]{acronym}

%-- Seitenstil ---------------------------
% Setzen der Seitenränder
\geometry{top=25mm,left=30mm,right=30mm,bottom=30mm,a4paper}
\setlength{    \marginparwidth}{20mm}

% Kein Einzug
\setlength{    \parindent}{0cm} 

% Konfiguration für das textpos
\setlength{    \TPHorizModule}{1mm}
\setlength{    \TPVertModule}{    \TPHorizModule}
\textblockorigin{0mm}{0mm}

% Kopf und Fusszeilen
\setlength{    \headheight}{15.2pt}
\pagestyle{fancy}

%-- Aufgabe mit Trennlinie --------------------------------
\newcounter{cntaufgabe}
\newcounter{cntfrage}
\setcounter{cntfrage}{1}
\newcommand{    \resetaufgabe}{%
\par
\vspace{10mm}
\leftskip=0cm
\setcounter{cntfrage}{1}
}
\newcommand{    \aufgabe}[1]{%
\stepcounter{cntaufgabe}
\resetaufgabe
\vspace{2ex}
\begin{flushright}
\leftskip=-2cm
\textbf{    \thecntaufgabe}
\end{flushright}
\hspace{5mm}
\textbf{#1}
\vspace{1mm}
\hrule
\vspace{2ex}%
}
%-- Frage mit Trennlinie --------------------------------
\newcommand{    \frage}[1]{%
\par
\vspace{5mm}
\leftskip=1.4cm
\alph{cntfrage})
\hspace{1mm}
\textit{#1}
\vspace{5mm}
\par
\leftskip=2cm
\stepcounter{cntfrage}
}


\begin{document}
%-- Deckblatt -----------------------------------
%    \input{allgemein/deckblatt.tex}
%-- Inhaltsverzeichnis --------------------------
\tableofcontents
\newpage 

\section{Title}

\subsection{Subtitle}

\aufgabe{Dies ist eine Aufgabe}
\blindtext
\setcounter{cntaufgabe}{16}
\setcounter{cntfrage}{16}
\aufgabe{Dies ist noch eine Aufgabe}
\frage{Was bedeutet ICMP?}
Internet Control Messages Protocol
\setcounter{cntfrage}{16}
\frage{Was bedeutet CSMA/CD?}
\blindtext
\aufgabe{Dies ist noch eine Aufgabe 23}
\setcounter{cntaufgabe}{111121545}
\aufgabe{Dies ist noch eine Aufgabe 34}
\begin{align}
e=mc^2
\end{align}
\resetaufgabe % muss mach aufgaben aufgerufen werden
\blindtext
\par
\blindtext
\begin{description}
  \item[First]    \hfill     \\
\The first item 
  \item[Second]    \hfill     \\
\ The second item
  \item[Third]    \hfill     \\
\ The third etc     \ldots
\end{description}

Plain text. 
\underline{    \hfill     \\
\}

\subsection{Another subtitle}

More plain text.
\blinddocument

%-- Appendix --------------------------
\appendix

\listoffigures
\listoftables

\end{document}

but unfortunately it looks so

enter image description here

can anyone please advise me how i can achieve it? Thx in advance Liz

Solved The solution that Thruston mentioned in the comments worked for me!

David Carlisle
  • 757,742
Liz
  • 11
  • Welcome to the site. You may visit http://meta.tex.stackexchange.com/q/1436 to get yourself familiarized further with our format. –  Sep 27 '13 at 07:11
  • Kindly consider posting a complete MWE starting from \documentclass{..} and ending at \end{document} so as to save us from some typing and guessing work (regarding the packages loaded) –  Sep 27 '13 at 07:13
  • What do the boxes represent and which of the elements should be where? – Werner Sep 27 '13 at 07:18
  • 1
    Your problem is that flushright creates a list with vertical space before and after. See this answer. Try replacing the whole flushright part with \leavevmode\llap{\bf\thecntaufgabe\kern2cm}. – Thruston Sep 27 '13 at 07:18
  • 1
    Perfect, thank you very much, it works like a charm. – Liz Sep 27 '13 at 07:32
  • @werner first left box the number, the box next to the number is the title and the bigone is just the some text – Liz Sep 27 '13 at 07:34
  • By the way how can i flag the question as answered? – Liz Sep 27 '13 at 07:36
  • @Thruston would have to write a proper answer, then you can accept that. (And by the way, use \bfseries, not \bf.) – Torbjørn T. Sep 27 '13 at 08:19
  • @Thruston \makebox[0pt][r]{\makebox[2cm][l]{...}} would use only documented LaTeX commands. – egreg Sep 27 '13 at 09:13
  • @TorbjørnT. I've added a proper answer now. T. – Thruston Sep 28 '13 at 15:17

1 Answers1

1

Replace the \flushright environment with something that does not create vertical space.

In plain/primitive TeX:

\leavevmode\llap{\bf\thecntaufgabe\kern2cm}

Or if you prefer to work at the LaTeX level:

\makebox[0pt][r]{\makebox[2cm][l]{\textbf{\thecntaufgabe}}}

as suggested in the comments.

Note that these two solutions are not quite the same: the original "plain" version sets 2cm of space after the number; the LaTeX version sets the number in a 2cm box. If you wanted the latter behaviour in plain Tex, you could try:

\leavevmode\llap{\hbox to 2cm{\bf\thecntaufgabe\hss}}

Also note that while one can freely mix TeX primitives, plain TeX macros, and LaTeX commands in any TeX document, there is an open question about whether this is a good idea. The general consensus on this forum seems to be that One Should Stick to LaTeX At All Times.

Personally I prefer sticking close to plain TeX so that I know more clearly what's going on, since LaTeX commands often have hidden surprises (as the OP discovered with flushright). But this does mean that I spent a lot of time reading the TeXbook. Your mileage may vary (as they say).

Thruston
  • 42,268
  • Don't use \bf but \bfseries – egreg Sep 28 '13 at 17:18
  • @egreg fair point, but \bf is shorter to type, and since normal LaTeX defines \bf as \normalshape\bfseries it was appropriate to the original question, since she's unlikely to want any bold italics in the section number box... – Thruston Sep 28 '13 at 18:07
  • \bf was declared obsolete around twenty years ago. The LaTeX kernel doesn't define it. Some classes do (in particular the standard ones, but just for backward compatibility). – egreg Sep 28 '13 at 19:16
  • Yeah sure I've read l2tabu as well, but I still think most of Knuth's original design is generally simpler and easier to type. And if you read my solution closely, you might notice that I was trying to show a Plain Tex solution in the first part. I put \textbf in the suggested LaTex solution. – Thruston Sep 28 '13 at 22:41
  • The answer is about LaTeX, not Plain TeX. I'm not against using low level constructions, when the corresponding LaTeX code would be unnecessarily heavy; but the font selection commands should be the LaTeX ones. Trying your answer with memoir would give a puzzling error. Don't confuse primitives with Plain TeX macros. – egreg Sep 28 '13 at 22:44
  • Well if you like I can put the LaTex solution at the top and push the plain solution further down. I only included both because they had both been discussed in the comments and I thought it might be informative for readers to see both. – Thruston Sep 28 '13 at 22:51