Centrare il contenuto di una colonna X

  • Creatore
    Topic
  • #67610
    Up
    0
    Down
    ::


    Ho il seguente codice compilabile:

    `% !TEX encoding = UTF-8 Unicode
    % !TEX TS-program = pdflatex

    \documentclass[a4paper]{article}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage[italian]{babel}
    \usepackage[urw-garamond]{mathdesign}
    \usepackage{tabularx}
    \usepackage{geometry}
    \geometry{top=2cm,bottom=2cm,left=2cm,right=2cm}

    \begin{document}

    \title{Griglia di correzione}
    \author{Verifica di Storia I, 2}
    \date{15 dicembre 2011}
    \maketitle

    \begin{center}
    \begin{tabularx}{\columnwidth}{|X|X|X|X|X|X|X|X|X|X|X|X|X|X|X|}
    \hline
    1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15\\
    \hline
    & & & & & & & & & & & & & & \\[1cm]
    \hline
    \end{tabularx}
    \end{center}

    \end{document}`

    Sorvoliamo sulla qualità: dovevo produrre velocemente una griglia in cui inserire le lettere risolutrici corrispondenti ad altrettanti item a scelta multipla.

    I numeri, però, sono allineati a sinistra, e io li vorrei centrati. Ho dato un occhio alla documentazione di tabularx, ma forse mi è sfuggito qualcosa. C’è modo di farlo? Forse con \newcolumntype di array?

    Si accettano suggerimenti anche per migliorare una griglia di questo tipo, se mi dovesse servire ancora.

    Ciao
    Tommaso

Visualizzazione 8 filoni di risposte
  • Autore
    Risposte
    • #67611
      lorenzo.pantieri
      Partecipante
        Up
        0
        Down
        ::


        `\newcolumntype{C}{>{\centering\arraybackslash}X}`
        In una delle passate versioni dell’Arte c’era (ti ricordi quelle due tabelle affiancate, ciascuna con due colonne, la prima l e la seconda X, la prima con il testo giustificato e l’altra con il testo allineato a sinistra? Parlavamo anche del pacchetto ragged2e o qualcosa di simile?)

        Ora non sono più così sicuro che abbiamo fatto a bene a togliere quella parte.

        Magari nella prossima edizione ce la rimettiamo, in fondo era una paginetta…

        Ciao,
        L.

      • #67612
        LuglioM26
        Partecipante
          Up
          0
          Down
          ::


          Ciao,

          così sembra funzionare.

          \begin{center}
          \begin{tabularx}{\columnwidth}{|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|>\centering X|}
          \hline
          1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 \tabularnewline
          \hline
          & & & & & & & & & & & & & & \tabularnewline[1cm]
          \hline
          \end{tabularx}
          \end{center}

          Stefano

        • #67613
          OldClaudio
          Partecipante
            Up
            0
            Down
            ::


            Perché invece di scrivere 15 volte >\centering X non scrivi cosi?
            `
            \begin{tabularx}{\columnwidth}{*{15}{>\centering X}}
            `

          • #67614
            Up
            0
            Down
            ::


            Anche io mi trovo nella stessa situazione…. il codice è il seguente:

            `

            \begin{tabularx}{\columnwidth}{ l *{3}{>\centering X}}

            \toprule

            \multirow{3}*{\bf Tipo di utente} & \multicolumn{3}{c}{ \bf Insiemi di funzioni} \\

            \cmidrule(lr){2-4}

            & Caricamento dati & Consultazione dati privati & Consultazione dati pubblici\\

            \midrule

            Utente ROOT & \checkmark & & \checkmark \\

            Utente comune & & \checkmark & \checkmark \\

            Utente pubblico & & & \checkmark \\

            \bottomrule

            \end{tabularx}

            `

            ma mi da quest’errore:

            `

            ! Misplaced \noalign.
            \midrule ->\noalign
            {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global \@…
            l.202 \end{tabularx}
            I expect to see \noalign only after the \cr of
            an alignment. Proceed, and I'll ignore this case.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Misplaced \noalign.
            \midrule ->\noalign
            {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global \@…
            l.202 \end{tabularx}
            I expect to see \noalign only after the \cr of
            an alignment. Proceed, and I'll ignore this case.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Misplaced \noalign.
            \midrule ->\noalign
            {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global \@…
            l.202 \end{tabularx}
            I expect to see \noalign only after the \cr of
            an alignment. Proceed, and I'll ignore this case.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.
            ! Extra alignment tab has been changed to \cr.
            \endtemplate
            l.202 \end{tabularx}
            You have given more \span or & marks than there were
            in the preamble to the \halign or \valign now in progress.
            So I'll assume that you meant to type \cr instead.

            `

            come fare?

          • #67615
            admin
            Amministratore del forum
              Up
              0
              Down
              ::


              Per prima cosa riporta un EMC, ovvero Esempio Minimo Compilabile: nel tuo codice mancano i pacchetti (anche se in questo caso sono facili da “trovare”) e la definizione di [tt]\checkmark[/tt]. Per farla breve, devi fornirci un codice di questo tipo

              \documentclass{}
              [tt][/tt]
              [tt][/tt]
              \begin{document}
              [color=#ff0000][tt][/tt][/color]
              \end{document}
              

              Ciao
              Orlando

            • #67616
              Up
              0
              Down
              ::

              lorenzo.pantieri” post=66601`\newcolumntype{C}{>{\centering\arraybackslash}X}`
              In una delle passate versioni dell’Arte c’era (ti ricordi quelle due tabelle affiancate, ciascuna con due colonne, la prima l e la seconda X, la prima con il testo giustificato e l’altra con il testo allineato a sinistra? Parlavamo anche del pacchetto ragged2e o qualcosa di simile?)

              Ora non sono più così sicuro che abbiamo fatto a bene a togliere quella parte.

              Magari nella prossima edizione ce la rimettiamo, in fondo era una paginetta…

              Ciao,
              L.

              Io direi che forse potremmo setacciare quello che abbiamo levato delle tabelle, per rimettere qualcosa.

              Ciao
              Tommaso

            • #67617
              lorenzo.pantieri
              Partecipante
                Up
                0
                Down
                ::

                illinguista1972″ post=74462Io direi che forse potremmo setacciare quello che abbiamo levato delle tabelle, per rimettere qualcosa.

                Certo, senza “forse”. Ripristiiamo la parte su come centrare o allineare a sinitra o a destra il testo di una colonna p o X. Gli esempi c’erano già: ricordo due tabelle affiancate con una colonna p, la prima con testo giustificato e la seconda con testo allineato a sinistra (e sillabato: serviva il pacchetto ragged2e, se ben ricordo).

                Rispetto a prima, potremmo essere meno sistematici e avere un tono più “an passàn”:

                Caro lettore, il trsto di una colonna p (o X) viene automaticamente giustificato, e di solito va benissimo così; se proprio proprio non ti va bene, per esempio perché la colonna p è molto stretta e la giustificazione viene brutta, il testo si può anche allineare a sinistra (o a destra, o cenrtato). Se lo vuoi anche sillabato c’è il pacchetto ragged2e. Guarda per esempio come viene la stessa tabella con una colonna p con testo risp. centrato e allineata a sinistra [segue codice].

                Ciao,
                L.

              • #67618
                OldClaudio
                Partecipante
                  Up
                  0
                  Down
                  ::


                  Il tuo problema nasce dal fatto che se l’ultima colonna contiene una specificazione tipo \centering, allora non si deve terminare la riga della tabella con \\, ma con \tabularnewline.

                  Questo nasce dal fatto che LaTeX non può capire se quel \\ indica che vuoi andare a capo nell’ultima cella per cominciare una nuova riga della stessa cella, oppre se vuoi terminare la cella e cominciare una nuova riga della tabella. \tabularnewline disambigua questa situazione.

                • #67619
                  Up
                  0
                  Down
                  ::


                  Sostituendo \\ con \tabularnewline funziona tutto. 😀

                  Grazie 1000 e scusate non aver riportato bene l’esempio.

              Visualizzazione 8 filoni di risposte
              • Devi essere connesso per rispondere a questo topic.

              Go to top