Hilfe bei Tabelle benötigt!

Tabellen und Grafiken erstellen und anordnen


Stimpy6
Forum-Newbie
Forum-Newbie
Beiträge: 5
Registriert: Mo 4. Mai 2015, 11:52

Hilfe bei Tabelle benötigt!

Beitrag von Stimpy6 »

Hallo an die Experten,

mir wurde hier in diesem Forum eine superschöne Tabelle (im Beispiel Tabelle 1) erstellt. Nun will ich die in meine Arbeit einfügen, aber es kommt eine Fehlermeldung "Command \mcb already defined". Der Grund ist wahrscheinlich, dass ich so eine ähnliche Tabelle (Tabelle 2 im Beispiel) davor schon erstellt habe.

Was muss ich tun, damit ich die beiden Tabellen in umgekehrter Reihenfolge in die Arbeit einfügen kann?
\documentclass[12pt,a4paper,pointednumbers,parindent]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{float} 
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{geometry}
\usepackage{setspace}
\usepackage{upquote}
\usepackage{multirow}
\usepackage{multicol} 
\usepackage{amsmath,amsthm}                                                                      
\usepackage{tabulary}
\usepackage{longtable}
\usepackage{arydshln}
\addtokomafont{captionlabel}{\bfseries} 
\usepackage{booktabs} 
\usepackage{array} 
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} 
\usepackage{blindtext}
\usepackage[absolute]{textpos}
\renewcommand{\footnotesep}{1.5em}



\begin {document}
\begin{table}[htb] 
  \newcommand\mcb[1]{\multicolumn{2}{c}{\bfseries#1}} 
  \newcommand\mcc[1]{\multicolumn{2}{C{\dimexpr6em+2\tabcolsep\relax}}{\bfseries#1}} 
  \captionabove{ Mean preference and standard deviation of the Codes 1 and 2 
    in every examined condition.} 
  \begin{tabular}{l*{8}{C{3em}}} 
    \toprule 
    & \mcb{Condition I} & \mcb{Conditon II} & \mcb{Condition III} & \mcb{Condition III} \\ 
    & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} 
      & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} \\ 
    & \textbf{M} & SD & \textbf{M} & SD & \textbf{M} & SD & \textbf{M} & SD \\ 
    \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9} 
    \textbf{Code 1} & 2,6 & 1,3 & 2,9 & 1,4 & 3,2 & 1,3 & 3,5 & 1,3 \\ 
    \textbf{Code 2} & 2,2 & 1,2 & 2,6 & 1,4 & 2,7 & 1,2 & 3,4 & 1,2 \\ 
    \bottomrule 
  \end{tabular} 
\end{table} 
\end{document}
% Die Tabelle, die ich davor habe sieht so aus: 
\begin {document}
 \newcommand\mcb[1]{\multicolumn{2}{c}{\bfseries#1}} 
  \begin{table}[htb] 

\noindent \textbf{Example 5}: Counting of the \textit{contentual units} in the story 'A dog' (For better visualization, one \textit{contentual unit} is printed in plain type, another unit in italic type.)

\vspace*{5mm}

     \begin{tabular}{p{.4cm}p{12cm}l} 
    \toprule 
    & \textbf{Type of participants' replies} & \textbf{Units} \\ 
    \midrule
    \textbf{5.1} & Michael can stay over.\textit{He can look forward to playing with the dog.}& 2 \\ 
    \textbf{5.2} & Thomas would be thrilled if Michael stayed over and \textit{he wants to make his stay even more pleasurable by mentioning the fact that he has a dog now} & 2  \\ 
        \textbf{5.3} & Yes, Michael can spend the night at Thomas's place. & 1 \\ 
    \textbf{5.4} & Thomas has no time for Michael anymore because he has to take care of his dog & 1  \\
    \bottomrule 
  \end{tabular} 
  
\end{table} 
\end{document}
Für alle Vorschläge bin ich sehr dankbar!

Viele Grüße,
Karin

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Bei der in Deinem MWE obereren Tabelle wird der Befehl innerhalb einer Gruppe (hier der table Umgebung) definiert und ist damit nur lokal gültig. Deshalb stört es bei der Reihenfolge nicht, dass Du den gleichen Befehl noch einmal neu global definierst. Tauschst Du aber die Tabellen bei der Neudefinition innerhalb der Gruppe festgestellt, dass Du den Befehl schon global definiert hast und Du bekommst die Fehlermeldung. Entweder Du definierst den Befehl stets nur lokal oder besser Du definierst ihn gleich in der Präambel, da Du ihn mehrfach und sogar mit gleicher Bedeutung nutzt.

Darüber hinaus solltest Du prüfen, ob Du die ganzen von Dir geladenen Pakete tatsächlich brauchst und ob Du weißt, was sie tun. Zum Beispiel scheinst Du geometry gar nicht nutzen zu wollen, aber es ändert Dir schon allein durch das Laden Deinen Satzspiegel - die zur Verfügung stehende Textbreite wird geringer und beide Tabellen sind zu breit. Bei der Exampletabelle habe ich für die erste Spalte l verwendet. Ach und die Angabe der Optionen für die Dokumentenklasse war auch nicht mehr aktuell. Dafür müsstest Du Warnungen erhalten haben.
\documentclass[12pt,numbers=enddot,parskip=false]{scrartcl} 
 \usepackage[utf8]{inputenc} 
 \usepackage[english]{babel} 

 \addtokomafont{captionlabel}{\bfseries} 
 \usepackage{booktabs} 
 \usepackage{array} 
 \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
 \newcommand\mcb[1]{\multicolumn{2}{c}{\bfseries#1}}
 \newcommand\mcc{}

 \begin {document} 
 \begin{table}[htb] 
 \textbf{Example 5}: Counting of the \textit{contentual units} in the story 'A dog' (For better visualization, one \textit{contentual unit} is printed in plain type, another unit in italic type.)
 \begin{tabular}{lp{12cm}l} 
 \toprule 
 & \textbf{Type of participants' replies} & \textbf{Units} \\ 
 \midrule 
 \textbf{5.1} & Michael can stay over.\textit{He can look forward to playing with the dog.}& 2 \\ 
 \textbf{5.2} & Thomas would be thrilled if Michael stayed over and \textit{he wants to make his stay even more pleasurable by mentioning the fact that he has a dog now} & 2 \\ 
 \textbf{5.3} & Yes, Michael can spend the night at Thomas's place. & 1 \\ 
 \textbf{5.4} & Thomas has no time for Michael anymore because he has to take care of his dog & 1 \\ 
 \bottomrule 
 \end{tabular}
 \end{table}
 \vspace*{5mm} 
 \begin{table}[htb] 
 \renewcommand\mcc[1]{\multicolumn{2}{C{\dimexpr6em+2\tabcolsep\relax}}{\bfseries#1}} 
 \captionabove{ Mean preference and standard deviation of the Codes 1 and 2 
 in every examined condition.} 
 \begin{tabular}{l*{8}{C{3em}}} 
 \toprule 
 & \mcb{Condition I} & \mcb{Conditon II} & \mcb{Condition III} & \mcb{Condition III} \\ 
 & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} 
 & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} \\ 
 & \textbf{M} & SD & \textbf{M} & SD & \textbf{M} & SD & \textbf{M} & SD \\ 
 \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9} 
 \textbf{Code 1} & 2,6 & 1,3 & 2,9 & 1,4 & 3,2 & 1,3 & 3,5 & 1,3 \\ 
 \textbf{Code 2} & 2,2 & 1,2 & 2,6 & 1,4 & 2,7 & 1,2 & 3,4 & 1,2 \\ 
 \bottomrule 
 \end{tabular} 
 \end{table} 
 \end{document} 
Gruß
Elke

Stimpy6
Forum-Newbie
Forum-Newbie
Beiträge: 5
Registriert: Mo 4. Mai 2015, 11:52

Beitrag von Stimpy6 »

Hallo liebe Elke,

vielen Dank schon wieder für Deine Hilfe! Es hat prima geklappt. Nun will ich aber noch so eine ähnliche Tabelle bastelt, allerdings kriege ich das nicht so schön hin wie Du damals. Speziell interessiert mich, wie ich die Code-Spalte etwas breiter gestalten könnte, so dass die Code-Nummer auch noch auf einer Linie erscheint?
Die Frage ist wahrscheinlich viel zu simpel, aber ich habe echt wenig Ahnung von dem Ganzen und jetzt, wo ich in der Arbeit so eine schöne Tabelle habe, dann dürfen die anderen ja auch nicht so stark abweichen. ;-). Aber das wäre jetzt echt meine letzte (für dieses Mal)!
\documentclass[12pt,numbers=enddot,parskip=false]{scrartcl} 
 \usepackage[utf8]{inputenc} 
 \usepackage[english]{babel} 

 \addtokomafont{captionlabel}{\bfseries} 
 \usepackage{booktabs} 
 \usepackage{array} 
 \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} 
 \newcommand\mcb[1]{\multicolumn{2}{c}{\bfseries#1}} 
 \newcommand\mcc{} 

\begin{document}

 \begin{table}[htb] 
 \renewcommand\mcc[1]{\multicolumn{2}{C{\dimexpr6em+2\tabcolsep\relax}}{\bfseries#1}} 
 \captionabove{Distribution of all codes in every examined condition.} 
 \begin{tabular}{l*{8}{C{3em}}} 
 \toprule 
 & \mcb{Condition I} & \mcb{Conditon II} & \mcb{Condition III} & \mcb{Condition III} \\ 
 & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} 
 & \mcc{Positive paraphrases} & \mcc{Negative paraphrases} \\ 
 & \textbf{CODE} & \textbf{MEAN} & \textbf{CODE} &\textbf{MEAN} & \textbf{CODE} & \textbf{MEAN} & \textbf{CODE} & \textbf{MEAN} \\ 
 \cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9} 
  &Code 7& 1.3 & Code 7 & 1.4 & Code 7 & 1.3 & Code 7 & 1.3 \\ 
  & Code 2 & 1.2 & Code 2 & 1.4 & Code 2 & 1.2 & Code 5 & 12 \\ 
 \bottomrule 
 \end{tabular} 
 \end{table} 

\end{document}
Lieben Dank!

Gruß,
Karin

esdd
Forum-Meister
Forum-Meister
Beiträge: 2561
Registriert: So 7. Feb 2010, 16:36

Beitrag von esdd »

Bitte schau, dass Du den Haken bei "BBCode in diesem Beitrag deaktivieren" (unterhalb des Eingabefeldes) entfernst und/oder Deine Einstellungen entsprechend änderst.

Die erste Spalte in Deiner Tabelle ist komplett leer. Die kannst Du entfernen. Außerdem reservierst Du für die doppelt breiten Zellen 7em+2\tabcolsep. Dann können die einfachen Zellen bis zu 3.5em breit sein, ohne dass die Tabelle breiter wird und das reicht dann auch für die Codenummern ;-)

\documentclass[12pt,numbers=enddot,parskip=false]{scrartcl} 
 \usepackage[utf8]{inputenc} 
 \usepackage[english]{babel} 

 \addtokomafont{captionlabel}{\bfseries} 
 \usepackage{booktabs} 
 \usepackage{array} 
 \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} 
 \newcommand\mcb[1]{\multicolumn{2}{c}{\bfseries#1}} 
 \newcommand\mcc{} 

\usepackage{showframe}
 \begin{document} 

 \begin{table}[htb] 
 \renewcommand\mcc[1]{\multicolumn{2}{C{\dimexpr7em+2\tabcolsep\relax}}{\bfseries#1}} 
 \captionabove{Distribution of all codes in every examined condition.} 
 \begin{tabular}{*{8}{C{3.5em}}} 
 \toprule 
\mcb{Condition I} & \mcb{Conditon II} & \mcb{Condition III} & \mcb{Condition III} \\ 
\mcc{Positive paraphrases} & \mcc{Negative paraphrases} 
& \mcc{Positive paraphrases} & \mcc{Negative paraphrases} \\ 
\textbf{CODE} & \textbf{MEAN} & \textbf{CODE} &\textbf{MEAN} & \textbf{CODE} & \textbf{MEAN} & \textbf{CODE} & \textbf{MEAN} \\ 
 \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}\cmidrule(lr){7-8} 
 Code 7& 1.3 & Code 7 & 1.4 & Code 7 & 1.3 & Code 7 & 1.3 \\ 
  Code 2 & 1.2 & Code 2 & 1.4 & Code 2 & 1.2 & Code 5 & 12 \\ 
 \bottomrule 
 \end{tabular} 
 \end{table} 
 \end{document}
Gruß
Elke

Stimpy6
Forum-Newbie
Forum-Newbie
Beiträge: 5
Registriert: Mo 4. Mai 2015, 11:52

Beitrag von Stimpy6 »

Hallo Elke,

vielen lieben Dank! Alles klappt jetzt prima!

Herzliche Grüße,

Karin

Antworten