title: Angular4 Material md-table Column Width AutoSizing Like Normal Table
body: <p>I'm using an md-table in an Angular 4 app since I'm using Material for other parts of the UI formatting. When I use a regular table with basically no CSS, the columns auto-format to fit the widest td element. With md-table, the columns are all set to the same width divided into the total table width, except for cells that are too wide and then it extends the cell and pushes the other cells in that row to the right. My regular table:</p>
  
  <pre><code>&lt;md-tab label="Data" &gt;
    &lt;md-card class="datacard"&gt;
      &lt;md-card-content&gt;
        &lt;div&gt;
          &lt;table class="datatable"&gt;
          ....
          &lt;/table&gt;
        &lt;/div&gt;
      &lt;/md-card-content&gt;
    &lt;/md-card&gt;
  &lt;/md-tab&gt;
  </code></pre>
  
  <p>The datatable css:</p>
  
  <pre><code>.datatable {
    border: 1px solid black;
    border-collapse: collapse;
    font-size: 10px;
    width: 100%;
    overflow-y:scroll;
  }
  </code></pre>
  
  <p>The md-table:</p>
  
  <pre><code> &lt;md-tab label="Data" &gt;
     &lt;md-card class="datacard"&gt;
       &lt;md-card-content&gt;
         &lt;div&gt;
          &lt;div class="datatableheader"&gt;
            &lt;md-input-container floatPlaceholder="never" id="filtercontainer"&gt;
              &lt;input mdInput #filter placeholder="Filter services" /&gt;
            &lt;/md-input-container&gt;
          &lt;/div&gt;
  
          &lt;md-table id="datatable" #datatable [dataSource]="resultDataSource" mdSort&gt;
  
            &lt;ng-container cdkColumnDef="Index"&gt;
              &lt;md-header-cell *cdkHeaderCellDef md-sort-header&gt;Index&lt;/md-header-cell&gt;
              &lt;md-cell *cdkCellDef="let result"&gt;{{result,Index}}&lt;/md-cell&gt;
            &lt;/ng-container&gt;
  
            &lt;ng-container cdkColumnDef="Service"&gt;
              &lt;md-header-cell *cdkHeaderCellDef md-sort-header&gt;Service&lt;/md-header-cell&gt;
              &lt;md-cell *cdkCellDef="let result"&gt;{{result.Service}}&lt;/md-cell&gt;
            &lt;/ng-container&gt;
  
            &lt;ng-container cdkColumnDef="Region"&gt;
              &lt;md-header-cell *cdkHeaderCellDef md-sort-header&gt;Region&lt;/md-header-cell&gt;
              &lt;md-cell *cdkCellDef="let result"&gt;{{result.Region}}&lt;/md-cell&gt;
            &lt;/ng-container&gt;
  
  
          &lt;/md-table&gt;
  
          &lt;md-paginator #paginator
                        [length]="results.length"
                        [pageIndex]="0"
                        [pageSize]="25"
                        [pageSizeOptions]="[5, 10, 25, 100]"&gt;
          &lt;/md-paginator&gt;
  
        &lt;/div&gt;
      &lt;/md-card-content&gt;
    &lt;/md-card&gt;
  &lt;/md-tab&gt;
  </code></pre>
  
  <p>I've helped fix some of the issue with overflow/overlap of text by setting <code>.mat-row { height: auto }</code>, but what I really want is for the table to do the same auto-fit with the columns as the normal table. I've attempted messing with the <code>flex</code> property and resetting width on the rows and columns to <code>initial</code>, but haven't found the right combination of css to get back the original formatting style of the table element.</p>