1

I have specified each tabular cell width exactly using formula

##1\linewidth-2\tabcolsep-1.5\arrayrulewidth as shown in the following code snippet:


\documentclass[dvips,dvipsnames,rgb]{book}

\usepackage[a4paper,margin=10mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{lscape}

\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newenvironment{MyTable}[4]%
{%
    \newcolumntype{A}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
    \begin{longtable}%
    {%
            |>{\scriptsize\centering\theNo}A{#1}<{}%
            |>{}A{#2}<{\centering\input{\jobname.tmp}}%
            |>{\centering\lstinputlisting{\jobname.tmp}}A{#3}<{}%
            |>{\scriptsize}A{#4}<{}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{& & & #1\tabularnewline\hline}


\usepackage{listings}
\lstset{%
language={PSTricks},
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue}%,
%backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}


\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}%
}

\def\endMyRow{%
        \end{VerbatimOut}%      
}



\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
%\clearpage
%\pagestyle{empty}
%Landscape starts here.
%\begin{landscape}
\begin{MyTable}{0.05}{.25}{0.4}{0.3}%
%=============
\begin{MyRow}
\pspicture*[showgrid](4,4)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](4,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%\end{landscape}
%Landscape stops here.
%\pagestyle{plain}
\end{document}

If I zoomed in the output, I will get the following result:

There is a gap on the most left table edge:

alt text


There is also a gap on the most right table edge:

alt text


I think it is caused by the rounding off done by LaTeX engine. Is there a way to solve this problem?


EDIT 1:

You might think of why I insist on getting the most perfect output. Because I want to create a "bubble" answer sheet using this table layout. Thus, high precision layout is a must. :-)

4
  • Not related to your problem, but \renewcommand{\theNo}{\stepcounter{No}\arabic{No}} is wrong. \theNo should expand to how to print the current value of the counter the same way that \theequation or \thepage do. It definitely shouldn't step the counter.
    – TH.
    Commented Dec 26, 2010 at 13:38
  • @TH, what is the side effect if I do like what I have done above? Commented Dec 26, 2010 at 13:40
  • I think my formula is not applicable for tables with more than 2 columns. Wait... :-) Commented Dec 26, 2010 at 14:11
  • Edits of the sort of your "EDIT 2" really aren't helpful at all. It's good that you gave an answer to your question (and you should accept it after 24-48 hours if it solves your problem); there was no need to edit the question. Commented Dec 28, 2010 at 12:07

1 Answer 1

1

I got the solution. :-)

\documentclass[dvips,dvipsnames,rgb]{book}

\usepackage[a4paper,hmargin=10mm,vmargin=40mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{lscape}
\setlength{\tabcolsep}{2mm}
\setlength{\arrayrulewidth}{2mm}
\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newenvironment{MyTable}[4]%
{%
    \newcolumntype{O}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \newcolumntype{I}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    ##1\linewidth-2\tabcolsep-\arrayrulewidth%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%
    \setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
    \begin{longtable}%
    {%
            |>{\scriptsize\centering\theNo}O{#1}<{}%
            |>{}I{#2}<{\centering\input{\jobname.tmp}}%
            |>{\centering\lstinputlisting{\jobname.tmp}}I{#3}<{}%
            |>{\scriptsize\bgroup\color{black}}O{#4}<{\egroup}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{&&&#1\tabularnewline\hline}


\usepackage{listings}
\lstset{%
language={PSTricks},
breaklines=true,
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue},
backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}


\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}%
}

\def\endMyRow{%
        \end{VerbatimOut}%      
}



\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
\color{red}%
%\clearpage
%\pagestyle{empty}
%Landscape starts here.
%\begin{landscape}
\begin{MyTable}{0.05}{0.3}{0.3}{0.35}%
%=============
\begin{MyRow}
\pspicture*[showgrid](3,3)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](3,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](3,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%\end{landscape}
%Landscape stops here.
%\pagestyle{plain}
\end{document}

For the most left or the most right COLUMN, the previous formula ##1\linewidth-2\tabcolsep-1.5\arrayrulewidth is applicable.

But for the remaining COLUMNs, the correct formula is ##1\linewidth-2\tabcolsep-\arrayrulewidth. :-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .