Page LayoutGetting vertical Position of the following text?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
CaptainProton
Posts: 15
Joined: Fri Dec 18, 2009 10:54 pm

Getting vertical Position of the following text?

Post by CaptainProton »

My task is to create sample solutions for exercises. To be flexible, I set up two environments "question" and "solution":

Code: Select all

\newenvironment{question}{\itshape}{}
\newenvironment{solution}{\\[2mm]\marginnote{-}}{}
Each solution is indicated with a dash in the margin. When the environments are used as follows, there is no problem and the dash is at the same vertical position as the beginning text of the answer:

Code: Select all

\begin{question}
  Question?
\end{question}\begin{solution}
  Answer
\end{solution}
ok
ok
ok.jpg (17.74 KiB) Viewed 2550 times
The obvious problem arises when the answer is for example a table or an enumeration:
problem.jpg
problem.jpg (17.13 KiB) Viewed 2550 times
My "solution" was to create several environments, one for tables, one for enumerations, one for images, one for equations, etc. and adjust the vertical alignment manually. However this isn't very elegant and I guess there must be a better way. What would you do?

Recommended reading 2024:

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

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

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Getting vertical Position of the following text?

Post by localghost »

The examdesign class (or related packages) may be better for this purpose.


Best regards
Thorsten
CaptainProton
Posts: 15
Joined: Fri Dec 18, 2009 10:54 pm

Getting vertical Position of the following text?

Post by CaptainProton »

localghost wrote:The examdesign class (or related packages) may be better for this purpose.
Thank you very much for your answer. I'm new to LaTeX and I'm impressed by the amount of possibilities. It seems there is a package for just about everything. However in this case, I don't think the examdesign package will solve the problem with the misaligned text in the margin (which is by the way just a small marker to assist the lecturer in quickly finding the sample solutions).
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Getting vertical Position of the following text?

Post by localghost »

I think at this point a minimal working example (MWE) is necessary just to see what you are doing. But I won't be able to look at it until after the Xmas holidays.
CaptainProton
Posts: 15
Joined: Fri Dec 18, 2009 10:54 pm

Getting vertical Position of the following text?

Post by CaptainProton »

localghost wrote:I think at this point a minimal working example (MWE) is necessary just to see what you are doing. But I won't be able to look at it until after the Xmas holidays.
Here you are:

Code: Select all

\documentclass[11pt,a4paper,fleqn]{article}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{marginnote}
\setlength{\parindent}{0em}

\reversemarginpar
\newenvironment{question}{\itshape}{}
\newenvironment{solution}{\\\marginnote{->}}{}

\begin{document}
  \begin{question}
    Question
  \end{question}\begin{solution}
    Solution with correctly aligned marker on the left
  \end{solution}\\
  
  \begin{question}
    Question
  \end{question}\begin{solution}
    \begin{enumerate}
      \item The marker should be at the same vertical position like this text
    \end{enumerate}
  \end{solution}
\end{document} 
Post Reply