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 have a longtable. This is my code

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amsxtra,amssymb,latexsym, amscd,amsthm}
\usepackage{indentfirst}
\usepackage[mathscr]{eucal}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{longtable}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{answers}
\theoremstyle{definition}
\newtheorem{cauhoi}{Quetion}
\Newassociation{ans}{Soln}{hint}
\renewcommand{\Solnlabel}[1]{{\bf  Answer #1}.}

\newenvironment{point}{%
\par\noindent
\begin{longtable}[t]{|p{14cm}|p{1.2cm}|}

\hline
}{%
\end{longtable}
}
\newcommand\diem[1]{ & \hfil \textbf{#1} \\ \hline}
\newcommand\tongdiem[1]{\dotfill [\textbf{#1} points]}
%\newcommand\tongdiem[1]{\fill [\textbf{#1} điểm]}
\usepackage{mathpazo}
\begin{document}
\setlength{\baselineskip}{16truept}
\Opensolutionfile{hint}[ans] 

\thispagestyle{empty}
\begin{center}
QUESTIONS
\end{center}
\begin{cauhoi}%1
(2 points) Find the domain of definition of the function \begin{equation*}
y = \sqrt{x^2 - 3x + 2} + \dfrac{1}{x + 4}.
\end{equation*}
\begin{ans}\tongdiem{2.5}
\begin{point}
First \diem{1}

This is 
\diem{1.0}

Second
\diem{0.5}

\end{point}
\end{ans}
\end{cauhoi}


\begin{cauhoi}%2
(2 points) Solve the equation \begin{equation*}
\sqrt{x + 1} + \sqrt{x + 2}-\sqrt{x + 3} =5.
\end{equation*}
\begin{ans}\tongdiem{2.5}
\begin{point}
First \diem{1}

Second
\diem{1.0}

Thirt
\diem{0.5}

\end{point}
\end{ans}
\end{cauhoi}


\vfill
\noindent \hrulefill

\Closesolutionfile{hint}
\newpage
\begin{center}
\large\textbf{ANSWER}
\end{center}
\Readsolutionfile{hint}

\end{document}

I want the out put has the form. Please help me. enter image description here

share|improve this question
    
don't use \noindent before longtable: it just causes a blank white line to be inserted before the table along with spurious parskip vertical space, and if you are unlucky, a bad page break. –  David Carlisle Nov 24 '12 at 11:31

1 Answer 1

up vote 5 down vote accepted

You can get the both the sides aligned using:

\begin{longtable}[t]{|p{14cm}|p{\dimexpr\linewidth-14cm-3\tabcolsep-2\arrayrulewidth\relax}@{}|}

enter image description here

This computes the required width of the right column so as to fill it.

If you just want to alignit on the right you can use the optional paraamter of longtable to specify that the table is to be right aligned:

\begin{longtable}[r]{|p{14cm}|p{1.2cm}|}

enter image description here

Notes:

  • The [showframe] option to the geometry package was used so that we could see the page margins. was used just to show the page margins.
  • Another option would be to use the tabularx package which allows for X column types that can expand to fill the specified width.
  • Further more you should have a look at the booktabs package for more professional looking tables.
  • As Marco Daniel commented, you should also have a look at the the ltxtable package which provides the functionality of longtable and tabularx together inside a longtable environment.
share|improve this answer
1  
Small hint: The optional argument of the environment longtable specify the horizontal alignment. Allowed parameter are: c, l and r. And I think ltxtable should be mentioned here. –  Marco Daniel Nov 24 '12 at 7:32
    
@MarcoDaniel: Thanks. I did not read that as an option, but you are correct the question does not specify whether the alinement is to just be on the right, or on both sides, which is what I had interpreted. –  Peter Grill Nov 24 '12 at 8:21
    
just a small remark: in the argument [r] no spaces are allowed for proper function, like <strike>[ r ]</strike> –  escalator May 7 at 11:07

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.