0

I have the following problem: I need to put variable length content into a fix-sized parbox the gets clipped with clipbox command. And want the content to be vertically centered. As long as the content fits into the parbox everthing is fine and it works. But if the text is longer then the available space, the vertical center alignment in combination with the clipbox command causes my text to be cropped. Please see the image below.

enter image description here

This is the code that demonstrates the problem:

\documentclass{scrartcl}

\usepackage{calc}
\usepackage{pstricks}

\begin{document}
    \begin{pspicture}(0,0)(\textwidth,\textheight)
        \newlength{\yPosition}
        \setlength{\yPosition}{\textwidth-5cm}
        \rput[lt](2cm,\yPosition){%
            \fbox{
                \clipbox{%
                    \parbox[t][1cm][c]{5cm}{%
                        short text
                    }%
                }%
            }
        }
        \addtolength{\yPosition}{-2cm}
        \rput[lt](2cm,\yPosition){%
            \fbox{
                \clipbox{%
                    \parbox[t][1cm][c]{5cm}{%
                        % short text
                        long text long text long text long text long text long text long text long text
                    }%
                }%
            }
        }
    \end{pspicture}
\end{document}

So, my question is: Is it possible to have the parbox content top-aligned if the content exceeds the size and center alignment if the content fits?

Thanks in advance

  • Do you mind making that a full minimal example? We cannot just copy a try that sniplet without adding to it. – daleif Mar 25 '15 at 14:16
  • Sorry, I completed the example. – nis Mar 25 '15 at 14:29
  • Pas, I never use pstricts. BTW: you might want to label this as pstricks as well, might attract more people. – daleif Mar 25 '15 at 14:37
  • Is it the \parbox height to adapt to the contents that you want? – Bernard Mar 25 '15 at 16:14
  • The content of the parbox comes from a PHP script and I have no influence on its length except limiting the size of the box and crop everything that's too long to avoid overlapping with other contents on the page. Does this answer your question? – nis Mar 25 '15 at 16:18
0

I got it working using the below code. I altered the inner parbox position to top and filled the space before and after the text with \vspace*{\fill}. This way the short text is vertically centered and the long text top aligned and cropped correctly. enter image description here

\documentclass{scrartcl}

\usepackage{calc}
\usepackage{pstricks}

\begin{document}
    \begin{pspicture}(0,0)(\textwidth,\textheight)
        \newlength{\yPosition}
        \setlength{\yPosition}{\textwidth-5cm}
        \rput[lt](2cm,\yPosition){%
            \fbox{
                \clipbox{%
                    \parbox[t][1cm][t]{5cm}{%
                        short text
                    }%
                }%
            }
        }
        \addtolength{\yPosition}{-2cm}
        \rput[lt](2cm,\yPosition){%
            \fbox{
                \clipbox{%
                    \parbox[t][1cm][t]{5cm}{%
                        \vspace*{\fill}
                        long text long text long text long text long text long text long text long text
                        \vspace*{\fill}
                    }%
                }%
            }
        }
    \end{pspicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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