1

Sorry maybe this question already answered. In latex i want to generate table and i'm new in table. I found some cool online tool https://www.tablesgenerator.com/latex_tables i draw my table now i paste to my latex code but it breaks my paper width. Then i google it and find some suggest they suggest \usepackage{tabularx} but i can't figure this out here is my code

\begin{table}[]
\begin{tabular}{|l|c|c|l|}
\hline
\multicolumn{1}{|c|}{Авбал зохих нийт оноо}                                                                       
& \multicolumn{1}{l|}{15 оноо} & \multicolumn{1}{l|}{} &                                      
\\ \hline

& \multicolumn{1}{l|}{}        & \multicolumn{1}{l|}{} &                                      
\\ \hline
\multicolumn{1}{|c|}{Гүйцэтгэлийн шалгуур}                                                                     
& Үнэлгээний эзлэх хувь        & CLOs хамаарал         & 
\multicolumn{1}{c|}{Багшийн үнэлгээ} \\ \hline
Хичээлийн ирц/оролцоо                                                                                      
& 10\%                         & 7,8                   &                                      
\\ \hline
Хэмжүүрийн тоног төхөөрөмж, програм хангамж ашиглах                                                        
& 20\%                         & 7                     &                                      
\\ \hline
\begin{tabular}[c]{@{}l@{}}Лабораторийн заавар, дарааллын дагуу 
хэмжилт, симуляци\\ гүйцэтгэх\end{tabular} & 20\%                         
& 8                     &                                      \\ 
\hline
Хэмжилт, туршилт, симуляцийн үр дүнг тохирох аргаар боловсруулах                                           
& 30\%                         & 9                     &                                      
\\ \hline
Лабораторийн тайлан бичилт, хамгаалалт                                                                     
& 10\% + 10\%                  & 10                    &                                      
\\ \hline
\multicolumn{1}{|c|}{Нийт үнэлгээ / хувиар/}                                                               
& \multicolumn{1}{l|}{}        & \multicolumn{1}{l|}{} &                                      
\\ \hline
\multicolumn{1}{|c|}{Нийт үнэлгээ /оноогоор/}                                                              
& \multicolumn{1}{l|}{}        & \multicolumn{1}{l|}{} &                                      
\\ \hline
\end{tabular}
\end{table}

i want this table width equals my page width. can you help me sorry for bad english

Mico
  • 506,678
ByamB4
  • 11
  • 2
  • 2
    Could you please extend your code to a compilable code? –  Mar 31 '19 at 06:02
  • Welcome to TeX.SE! – Mico Mar 31 '19 at 07:08
  • 1
    Which document class are you using? Which packages? Please edit you post and complete your code snippet. See also: https://tex.stackexchange.com/questions/332902/my-table-doesnt-fit-what-are-my-options – CarLaTeX Mar 31 '19 at 07:37

1 Answers1

1

You haven't exactly provided a lot of information about your document setup, so I've had to make some (almost certainly less than ideal) assumptions about the document class, the width of the text block, font packages, and the use of the babel package in order to create a compilable example.

Your tabular environment is wider than the textblock because you're not allowing line breaks to occur in the header cells or in the cells in the left-hand column.

The following solution uses a tabularx environment to allow automatic line-breaking. I've set up two column types, L and C, that are based on the X column type while making it easier to specify unequal column widths. (Note that 2.1+0.7+2*0.6=4; 4 is also the number of columns of type X.) The solution also gets rid of all vertical lines -- they're not needed! really! -- and uses fewer but well-spaced horizontal lines. The code can be compiled with pdfLaTeX, XeLaTeX, and LuaLaTeX; for the following screenshot I chose LuaLaTeX.

enter image description here

\documentclass{article}
\usepackage[russian]{babel} % or some other language?
\usepackage[lining]{ebgaramond}
\usepackage{ebgaramond-maths} % optional

\usepackage{booktabs} % for well-spaced horizontal lines
\usepackage{tabularx,ragged2e}
\newcolumntype{L}[1]{%
   >{\RaggedRight\arraybackslash%
     \hsize=#1\hsize\linewidth=\hsize%
     \hangindent1em\hangafter1}X}
\newcolumntype{C}[1]{%
   >{\Centering\arraybackslash%
     \hsize=#1\hsize\linewidth=\hsize}X}

\begin{document}
\begin{table}
%% allow automatic line breaking in all four columns
\begin{tabularx}{\textwidth}{@{} L{2.1} C{0.7} *{2}{C{0.6}} @{}}
\toprule
\multicolumn{1}{c}{Авбал зохих нийт оноо} & 15 оноо &  & \\ 
\addlinespace
\multicolumn{1}{c}{Гүйцэтгэлийн шалгуур} & Үнэлгээний эзлэх хувь 
   & CLOs хамаарал & Багшийн үнэлгээ \\ 
\midrule
Хичээлийн ирц\slash оролцоо & 10\% & 7,8 & \\ 
\addlinespace
Хэмжүүрийн тоног төхөөрөмж, програм хангамж ашиглах & 20\% & 7 & \\ 
\addlinespace
Лабораторийн заавар, дарааллын дагуу хэмжилт, симуляци гүйцэтгэх & 20\% & 8 & \\ 
\addlinespace
Хэмжилт, туршилт, симуляцийн үр дүнг тохирох аргаар боловсруулах & 30\% & 9 & \\ 
\addlinespace
Лабораторийн тайлан бичилт, хамгаалалт & 10\% + 10\% & 10 & \\ 
\midrule
\multicolumn{1}{c}{Нийт үнэлгээ / хувиар/} & & & \\ 
\addlinespace
\multicolumn{1}{c}{Нийт үнэлгээ / оноогоор/} & & & \\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}
Mico
  • 506,678